GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - teliosdev/under: A simple rust HTTP server library.

BranchesTags
Open more actions menu

Latest commit

 

History

28 Commits
28 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
under
under
 
 
under_derive
under_derive
 
 
.gitignore
.gitignore
 
 
Cargo.toml
Cargo.toml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

Under

Version docs.rs License CI

A very simple HTTP server framework. This serves as a small layer between your application code and Hyper.

Right now, this layer is very bare-bones - however, the intent is to add on to this whenever patterns with the code become obvious. If you encounter any, feel free to create an issue.

Setting Up

The simplest way to set up a server is by using under::Router:

let mut http = under::http();
http.at("/").get(under::endpoints::simple(under::Response::empty_204));
http.listen("localhost:8080").await.unwrap();

This will cause the application to run an HTTP server on port 8080 locally; running GET / would return 204 No Content.

The router accepts all kinds of verbs:

http.at("/users")
    .get(users::index)
    .post(users::create)
    .at("/{id}")
        .get(users::show)
        .put(users::update)
        .delete(users::delete);

Note the hirearchal structure of the at calls - if the latter at is called underneath an already existing at, then the paths are joined. The above example is equiavlent to:

http.at("/users")
    .get(users::index)
    .post(users::create);
http.at("/users/{id}")
    .get(users::show)
    .put(users::update)
    .delete(users::delete);

For verbs that are not included by default, you may use the method function to declare one:

http.at("/users/{id}")
    .method(hyper::Method::from_bytes(b"SOMETHING").unwrap(), users::something);

Or, if you want to capture all methods, you can use the all function to do so:

http.at("/users/{id}").all(users::all);

Endpoints

When declaring a path, it must route to an endpoint - the argument passed into the verb function, e.g. get(users::show). The value passed must implement under::Endpoint. under::Endpoint is implemented for fn(under::Request) -> impl Future<Output = Result<under::Response, anyhow::Error> + Send + Sync + 'static; so, declaring an endpoint can be as simple as:

async fn index(request: under::Request) -> Result<under::Response, anyhow::Error> {
    todo!()
}

and used as above. This library also comes with a few built-in endpoints in under::endpoints.

About

A simple rust HTTP server library.

Topics

http-serverrust

Resources

Readme
MIT license
Activity

Stars

5 stars

Watchers

0 watching

Forks

1 fork
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.