10 releases (4 breaking)

0.5.5 Nov 19, 2023
0.5.4 Nov 18, 2023
0.4.0 Nov 13, 2023
0.3.0 Nov 11, 2023
0.1.0 Nov 10, 2023

#4 in #response-status

Download history 14/week @ 2024-02-19 4/week @ 2024-02-26 6/week @ 2024-03-11 176/week @ 2024-04-01

182 downloads per month

MIT license

17KB
484 lines

direct_http

An simple and low-level rust REST API library.

Response

Response is a struct that represents the HTTP response.
It contains a status enum that represents the status code, an optional message of type String, and optional data of type Value.

pub struct Response {
  status: Status,
  message: Option<String>,
  data: Option<Value>,
}

You should always construct the Response using the status you want to return.
Passing an message or data is optional.

response

let response = Response::status(Status::Ok)

response with data

let response = Response::status(Status::Ok).data(ENCODE!(user))

response with message

let response = Response::status(Status::Ok).message("Hello world!")

response with data and message

let response = Response::status(Status::Ok).message("Hello world!").data(ENCODE!(user))

Dependencies

~5–16MB
~195K SLoC