- macro-less and type-safe APIs for intuitive and declarative code
- various runtimes are supported:
tokio,async-std,smol,nio,glommioandworker(Cloudflare Workers),lambda(AWS Lambda) - extremely fast, no-network testing, well-structured middlewares, Server-Sent Events, WebSocket, highly integrated OpenAPI document generation, ...
Quick Start
- Add to
dependencies:
[]
= { = "0.23", = ["rt_tokio"] }
= { = "1", = ["full"] }
- Write your first code with Ohkami : examples/quick_start
use *;
use status;
async
async
async
- Run and check the behavior :
Feature flags
"rt_tokio", "rt_async-std", "rt_smol", "rt_nio", "rt_glommio" : native async runtime
"rt_worker" : Cloudflare Workers
Works with worker crate.
then <project dir> will have wrangler.toml, package.json and a Rust library crate.
A #[ohkami::worker] (async/sync) fn returning Ohkami is the Worker definition.
Local dev by npm run dev and deploy by npm run deploy !
See README of template for details.
Or, here are Workers + OpenAPI template and Workers + SPA with Yew template.
"rt_lambda" : AWS Lambda
experimental
- Both
Function URLsandAPI Gatewayare supported - WebSocket is not supported now
- Please let us know any bugs or unexpected behavior on PR!
Works with lambda_runtime crate ( and tokio ).
cargo lambda will be good partner.
Let's :
lambda_runtime::run(your_ohkami) make you_ohkami run on Lambda Function.
Local dev by
and deploy by
See
- README of template
- Cargo Lambda document
for details.
"sse" : Server-Sent Events
Ohkami responds with HTTP/1.1 Transfer-Encoding: chunked.
Use some reverse proxy to do with HTTP/2,3.
use *;
use DataStream;
use ;
async
async
"ws" : WebSocket
Ohkami only handles ws://.
Use some reverse proxy to do with wss://.
use *;
use ;
async
async
- On
"rt_worker", both normal ( stateless ) WebSocket and WebSocket on Durable Object are available! - On
"rt_lambda", WebSocket is currently not supported.
"openapi" : OpenAPI document generation
"openapi" provides highly integrated OpenAPI support.
This enables macro-less, as consistent as possible OpenAPI document generation, where most of the consistency between document and behavior is automatically assured by Ohkami's internal work.
Only you have to
- Derive
openapi::Schemafor all your schema structs - Make your
Ohkamicall.generate(openapi::OpenAPI { ... })
to generate consistent OpenAPI document.
You don't need to take care of writing accurate methods, paths, parameters, contents, ... for this OpenAPI feature; All they are done by Ohkami.
Of course, you can flexibly customize schemas ( by hand-implemetation of Schema ), descriptions or other parts ( by #[operation] attribute and openapi_* hooks ).
use *;
use status;
use openapi;
// Derive `Schema` trait to generate
// the schema of this struct in OpenAPI document.
// `#[openapi(component)]` to define it as component
// in OpenAPI document.
async
// (optionally) Set operationId, summary,
// or override descriptions by `operation` attribute.
/// This doc comment is used for the
/// `description` field of OpenAPI document
async
async
- Currently, only JSON is supported as the document format.
- When the binary size matters, you should prepare a feature flag activating
ohkami/openapiin your package, and put all your codes aroundopenapibehind that feature via#[cfg(feature = ...)]or#[cfg_attr(feature = ...)]. - In
rt_worker,.generateis not available becauseOhkamican't have access to your local filesystem bywasm32binary on Minifalre. So ohkami provides a CLI tool to generate document from#[ohkami::worker] Ohkamiwithopenapifeature.
"nightly" : nightly-only functionalities
- try response
Snippets
Typed payload
builtin payload : JSON, Text, HTML, URLEncoded, Multipart
use *;
use status;
/* Deserialize for request */
/* Serialize for response */
async
Typed params
use *;
async
async
async
async
Middlewares
Ohkami's request handling system is called "fangs", and middlewares are implemented on this.
builtin fang :
Context( typed interaction with reuqest context )CORS,JWT,BasicAuthTimeout( native runtime )Enamel( experimantal; security headers )
use *;
;
/* utility trait; automatically impl `Fang` trait */
async
Database connection management with Context
use *;
use status;
use ;
async
async
Static directory serving
use *;
async
File upload
use *;
use status;
use ;
async
Pack of Ohkamis
use *;
use status;
async
async
async
async
Testing
use *;
use *; // <--
async
Supported protocols
- HTTP/1.1
- HTTP/2
- HTTP/3
- HTTPS
- Server-Sent Events
- WebSocket
MSRV ( Minimum Supported Rust Version )
Latest stable
License
ohkami is licensed under MIT LICENSE ( LICENSE or https://opensource.org/licenses/MIT ).