Argos makes it easy to create a stand-alone web application backend server.
API
functionYou can define your api function with a macro-attribute:
```rust
pub fn hello(req: HttpRequest) -> Result
this function define a http interface with
GET
method, and url path is/api/hello
.
You can start your server like this: ```rust
async fn main() { let server = Server::builder(([127, 0, 0, 1], 3000).into()) .build() .await .unwrap(); server.start().await.unwrap(); } ```
Your server will bind in 127.0.0.1:3000
, so you can send a http request to call this API:
shell
curl http://127.0.0.1:3000/api/hello?name=liudao
You can define a filter to filt the request:
```rust
pub fn pathfilter(mut req: HttpRequest) -> Chain { let attr = req.attributesmut(); attr.insert("kk".tostring(), "value".tostring()); // let method = req.methodmut(); if req.headers().containskey("token") { Chain::Continune(req) } else { let mut returnerr = ReturnError::new( 401, "not authorized".tostring(), ); returnerr.headers.append("filter", HeaderValue::fromstr("rejected").unwrap()); Chain::Reject(returnerr) }
} ```
Filter now only support
path_pattern
, usingregexp
. The attributeorder
represents the priority of the filter, the smaller the number, the higher the priority.
See more examples in core/examples
.
Argos is provided under the MIT license. See LICENSE.