httpageboy

Crates.iohttpageboy
lib.rshttpageboy
version1.0.1
sourcesrc
created_at2024-11-04 05:41:52.036767
updated_at2024-11-14 20:01:43.419511
descriptionPackage for handling HTTP request and response transmission on the server side, without additional processing.
homepage
repositoryhttps://gitlab.com/numanope/eqeqo/bazoj/rs-http-server
max_upload_size
id1434571
size28,142
fahedsl (fahedslx)

documentation

README

eqeqo - HTTPageboy

A basic package for handling HTTP request and response transmission on the server side, without additional processing.

  • Requests can be any HTTP request.

  • Routes are formed by the path, the HTTP request type, and the function to handle the request. The function must return a Response instance.

  • Responses type are identified by the content type and are returned as bytes to browsers.

Example

Creating a simple server:

	use server_base::{ ServerBase, Rt, Request, Response, StatusCode };

	// Demo route handler (valid empty answer)
	fn demo_handle_test_get (_request: &Request) -> Response {
		return Response {
			status: StatusCode::Ok.to_string(),
			content_type: String::new(),
			content: "test-get".as_bytes().to_vec(),
		}
	}
	// Another demo route handler (also empty)
	fn demo_handle_test_post (_request: &Request) -> Response {
		return Response {
			status: StatusCode::Ok.to_string(),
			content_type: String::new(),
			content: "test-post".as_bytes().to_vec(),
		}
	}

	fn main() {
		// Location to run, in this example is defined to an arbitrary ip and port.
		let serving_url: &str  = "127.0.0.1:7878";
		// Define number of requests the server will be able to run at the same time.
		let threads_number: u8 = 10;
		// Create a new server
		let server = ServerBase::new(serving_url, threads_number, None).unwrap();
		// Define routes and http method allowed, and link them to request handlers defined previously.
		server.add_route("/test_route", Rt::GET, demo_handle_test_get);
		server.add_route("/test_route", Rt::POST, demo_handle_test_post);
		// Start serving
		server.run();
		// ...
		// Stop and kill the server
		server.stop();
	}

Dependencies

There are no external dependencies for production. :) There are two deps for testing only.

License

Copyright (c) 2024 fahedsl This project is licensed under the MIT License. For more details, refer to the MIT License.

Commit count: 39

cargo fmt