Code Monkey home page Code Monkey logo

axum-demo's Introduction

Axum demo

Axum: ergonomic and modular web framework built with Tokio, Tower, and Hyper.

  • Route requests to handlers with a macro free API.
  • Declaratively parse requests using extractors.
  • Simple and predictable error handling model.
  • Generate responses with minimal boilerplate.
  • Take full advantage of the tower and tower-http ecosystem of middleware, services, and utilities.

Hyper: A fast and correct HTTP implementation for Rust.

  • HTTP/1 and HTTP/2
  • Asynchronous design
  • Leading in performance
  • Tested and correct
  • Extensive production use
  • Client and Server APIs

tower-http: a collection of HTTP specific middleware and utilities built with Tower's Service trait.

  • Trace: Easily add high level tracing/logging to your application. Supports determining success or failure via status codes as well as gRPC specific headers. Has great defaults but also supports deep customization.
  • Compression and Decompression: Automatically compress or decompress response bodies. This goes really well with serving static files using ServeDir.
  • FollowRedirect: Automatically follow redirection responses.

http: a general purpose library of common HTTP types, for examples http::{Request, Response, StatusCode}

Vocabulary

  • Handler: an async function that accepts zero or more “extractors” as arguments and returns something that can be converted into a response.
  • Routing: between handlers and request paths
  • Extractor: a type that implements FromRequest. Extractors are how you pick apart the incoming request to get the parts your handler needs.
  • Building responses: anything that implements IntoResponse can be returned from a handler
  • Middleware: used to decorate the application, providing additional functionality

Demo cases

  • static assets handle
  • index page
  • form submit: login
  • json submit: REST API
  • json output: struct and json!() macro
  • query: /search?q=java
  • Path variables/params /user/:id
  • 404 handler: Separate net("/") and handler_404()

Docker support

Refer from Packaging a Rust web service using Docker

docker build -t axum-demo .
docker run -p 3000:3000 axum-demo

Or you can refer https://kerkour.com/blog/rust-small-docker-image/

References

axum-demo's People

Contributors

linux-china avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

axum-demo's Issues

GLIBC not found

After building a docker image, I run the following docker command and I get an error that glibc is missing (running locally on Mac M1).

docker run -p 3000:3000 axum-demo

./axum-demo: /lib/aarch64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by ./axum-demo)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.