Skip to content

Commit

Permalink
Added README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Padi2312 committed Mar 10, 2024
1 parent 530344a commit 148b47d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
name = "surfer"
version = "0.3.0"
edition = "2021"
description = "A simple web server"
authors = ["Patrick Arndt <patrick.arndt.99@web.de>"]
description = "A small backend \"framework\" for Rust"
authors = ["Patrand"]
license = "MIT"
readme = "README.md"

[dependencies]
async-std = { version = "1.12.0", features = ["attributes"] }
Expand Down
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<p align="center">
<img src="./docs/surfer_logo.png" alt="Surfer Logo" width="200">
</p>

<h1 align="center">Surfer</h1>

<p align="center">
<strong>A lightweight, asynchronous backend framework for Rust with Rust</strong>
</p>

It's a <span style="font-size: 7px;">simple</span>, <span style="font-size: 12px;">lightweight</span> and asynchronous backend framework for Rust. It's built on top of `async-std` and provides ~~easy~~ route registration and handling of HTTP requests. It also provides built-in response structs for response creation and JSON response support for structs with Serialize and Deserialize implemented.

## 🚀 Features
- Asynchronous handling of HTTP requests (using async-std)
- Easy route registration with the `route!` macro
- Built-in response structs for easy response creation
- JSON response support for structs with Serialize and Deserialize implemented
- Use the `#[surfer_launch]` macro ~~to start the server~~ to not have to write `#[async_std::main]` (internally it's the same thing :D)

## 📦 Installation

Clone the repository and add the following to your `Cargo.toml`:

```toml
[dependencies]
surfer = { version = "0.3.0", path = "path/to/surfer" }
```

## 📚 Example Usage
```rust
extern crate surfer;

use serde_json::json;
use surfer::request::Method::GET;
use surfer::request::Request;
use surfer::response::json_response::JsonResponse;
use surfer::response::{IntoResponse, Response};
use surfer::route;
use surfer::server::Server;
use surfer_macros::surfer_launch;

async fn index(_: Request) -> Response {
let json_obj = json!({
"message": "Hello, Surfer!"
});
JsonResponse {
status_code: 200,
headers: None,
body: json_obj,
}
.into_response()
.await
}

#[surfer_launch]
async fn main() {
let mut server = Server::new(None, None);
server.register_route(route!(GET, "/", index));
server.listen().await;
}
```

## 📖 Documentation
For more detailed documentation, get known to the source code 🫠
3 changes: 1 addition & 2 deletions bin/main_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ use surfer::response::{IntoResponse, Response};
use surfer::route;
use surfer::server::Server;
use surfer_macros::surfer_launch;

async fn index(_: Request) -> Response {
let json_obj = json!({
"message": "Hello, Surfer!"
});
JsonResponse {
status_code: 200,
headers: Default::default(),
headers: None,
body: json_obj,
}
.into_response()
Expand Down
Binary file added docs/surfer_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 148b47d

Please sign in to comment.