From 591718d87d351b0acff0696b4d5a25b0018795b3 Mon Sep 17 00:00:00 2001 From: rtritto Date: Wed, 20 Nov 2024 10:42:53 +0100 Subject: [PATCH] Add porting example of the may_minihttp cargo --- examples/porting-may_minihttp/Cargo.toml | 14 +++++++++++ examples/porting-may_minihttp/README.md | 19 +++++++++++++++ examples/porting-may_minihttp/package.json | 27 ++++++++++++++++++++++ examples/porting-may_minihttp/src/lib.rs | 2 ++ 4 files changed, 62 insertions(+) create mode 100644 examples/porting-may_minihttp/Cargo.toml create mode 100644 examples/porting-may_minihttp/README.md create mode 100644 examples/porting-may_minihttp/package.json create mode 100644 examples/porting-may_minihttp/src/lib.rs diff --git a/examples/porting-may_minihttp/Cargo.toml b/examples/porting-may_minihttp/Cargo.toml new file mode 100644 index 0000000..aa11741 --- /dev/null +++ b/examples/porting-may_minihttp/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "porting-may_minihttp" +version = "0.1.0" +description = "Porting of the crate may_minihttp" +license = "MIT" +edition = "2021" +exclude = ["index.node"] + +[lib] +crate-type = ["cdylib"] + +[dependencies] +neon = "1.1.0-alpha.1" +may_minihttp = "0.1.11" diff --git a/examples/porting-may_minihttp/README.md b/examples/porting-may_minihttp/README.md new file mode 100644 index 0000000..6e5c0f9 --- /dev/null +++ b/examples/porting-may_minihttp/README.md @@ -0,0 +1,19 @@ +# porting-may_minihttp + +Porting of the crate [may_minihttp](https://crates.io/crates/may_minihttp) ([GitHub repository](https://github.com/Xudong-Huang/may_minihttp)). + +## Usage + +```js +const { HttpServer, HttpService, Request, Response } = require("."); + +class HelloWorld extends HttpService { + call(_req: Request, res: Response) { + res.body("Hello, world!"); + } +} + +const server = HttpServer(HelloWorld).start("0.0.0.0:8080").unwrap(); + +server.join().unwrap(); +``` diff --git a/examples/porting-may_minihttp/package.json b/examples/porting-may_minihttp/package.json new file mode 100644 index 0000000..77ca6b6 --- /dev/null +++ b/examples/porting-may_minihttp/package.json @@ -0,0 +1,27 @@ +{ + "name": "porting-may_minihttp", + "version": "0.1.0", + "description": "Porting of the crate may_minihttp", + "main": "index.node", + "scripts": { + "build": "cargo-cp-artifact -nc index.node -- cargo build --message-format=json-render-diagnostics", + "install": "npm run build", + "test": "cargo test" + }, + "license": "MIT", + "devDependencies": { + "cargo-cp-artifact": "^0.1.9" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/neon-bindings/examples.git" + }, + "keywords": [ + "Neon", + "Examples" + ], + "bugs": { + "url": "https://github.com/neon-bindings/examples/issues" + }, + "homepage": "https://github.com/neon-bindings/examples#readme" +} diff --git a/examples/porting-may_minihttp/src/lib.rs b/examples/porting-may_minihttp/src/lib.rs new file mode 100644 index 0000000..d4d3df5 --- /dev/null +++ b/examples/porting-may_minihttp/src/lib.rs @@ -0,0 +1,2 @@ +use neon::prelude::*; +use may_minihttp::{BodyReader, HttpServer, HttpService, HttpServiceFactorye, Request, Response};