httpbeast Documentation

repository·master·Indexed 19 days ago

https://github.com/dom96/httpbeast

A highly performant, multi-threaded HTTP 1.1 server written in Nim. It utilizes OS-level APIs like epoll and kqueue for efficient I/O and supports HTTP pipelining and async/await via Nim's asyncdispatch. Designed for speed with on-demand parsing, it requires the --threads:on flag for parallelization and does not support Windows.

Tokens
478
Snippets
1
Records
2
Agent score
17%

What's inside httpbeast

  1. Key features and requirements of httpbeast

    master

    Performance and Parallelization

    • Automatic Parallelization: Enabled by compiling with the --threads:on flag.
    • Efficient I/O: Built on Nim's selectors module, utilizing epoll on Linux and kqueue on macOS.
    • On-demand Parsing: Only requested data is parsed to optimize performance.
    • HTTP Pipelining: Supported.

    Integration and Compatibility

    • Async Support: Integrates with Nim's asyncdispatch, allowing the use of async/await within request callbacks.
    • OS Support: Does not support Windows by design (uses epoll-like APIs).

    Security Warning

    This library is not hardened against common HTTP security exploits. For production use, it is recommended to run httpbeast behind a reverse proxy like nginx.

  2. Get started with httpbeast

    master

    To use httpbeast, create a Nimble package and a source file. Ensure you have httpbeast listed as a dependency in your .nimble file and that you compile with --threads:on to enable automatic parallelization.

    1. Configure your .nimble file

    Include httpbeast >= 0.4.0 in your dependencies.

    2. Implement your request handler

    Import httpbeast and use the run(onRequest) function. The handler receives a Request object and returns a Future[void]. You can use req.httpMethod, req.path, and req.send() to manage responses.

    3. Run the application

    Use nimble c -r <your_file>.nim to compile and run.

    import options, asyncdispatch
    import httpbeast
    
    proc onRequest(req: Request): Future[void] =
      if req.httpMethod == some(HttpGet):
        case req.path.get()
        of "/":
          req.send("Hello World")
        else:
          req.send(Http404)
    
    run(onRequest)