Giter Site home page Giter Site logo

mjkillough / aitch Goto Github PK

View Code? Open in Web Editor NEW
18.0 18.0 1.0 136 KB

aitch is a simple, lightweight toolkit for building HTTP servers in Rust, loosely based on Go's net/http.

License: MIT License

Rust 100.00%
async futures http http-server hyper net-http rust tokio

aitch's People

Contributors

mjkillough avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

neochow

aitch's Issues

Should the error type be Box<Error>?

We currently define aitch::Error to be an alias for Box<Error>.

This was because:

  • We wanted middleware to be as generic as possible, while requiring as few type parameters as possible. The hope that this would encourage users to create and share re-usable middleware, without having to specify an error type everywhere.
  • It wasn't clear what downstream middleware/servers could do with the information in an error type. If a handler returns an error type, it's unlikely that the application could do much more than return a generic HTTP 500.

Since making this decision, we added the handler::static_files handlers, which attempt to catch io::Error and display a HTTP 404. These currently downcast the Box<Error>, which feels a little gross. Is there a better way?

Would aitch be more powerful if it somehow allowed users to specify a custom error type? What would that API look like?

Feedback very welcome!

Should the aitch crate be split out into separate crates?

The aitch crate was originally meant to define just the types necessary to create handlers/middlewares/bodies. The server backends and other middlewares were going to be defined in separate crates.

For ease of development, the other features were added to the main aitch crate, behind default-on optional cargo features. Should they be split out into separate crates? It would keep the main aitch crate small (as was intended), but make it more difficult for end-users to use.

The crate could be split by:

  • aitch_hyper: Hyper back-end.
  • aitch_tiny_http: tiny_http back-end
  • aitch_json: Serde support
  • aitch_static_files: Static file serving. (Although this might give the impression that it's production ready).
  • aitch_simple_router: SimpleRouter, although maybe there should be a better aitch_router crate.

Should there be a generic Server trait?

We currently have implementations for two back-ends: Hyper and HTTP. Both expose a Server struct with a common interface.

So far they do not share a trait, but perhaps they should? Would this limit us from supporting other back-ends in the future, if they're unable to implement the trait for whatever reason? (Maybe they can't get the local addr they're bound to).

Would applications ever want to be generic over the server back-end used? That would be the biggest motivating factor for adding a trait.

Create a production ready request Router

The crate provides SimpleRouter, which is primarily an example of how one might build a router or other complex middleware.

We should also provide (possible in a separate crate), a more production ready router, with features like:

  • matching request method
  • more complex path matching
  • passing parameters from path into handler functions

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.