beast icon indicating copy to clipboard operation
beast copied to clipboard

Robust HTTP Server Example

Open vinniefalco opened this issue 4 years ago • 18 comments

It would be nice to have a new example HTTP server that supports POST to upload files, GET / to see the list of files, and GET to download a file.

vinniefalco avatar Mar 24 '21 17:03 vinniefalco

I am currently working on that... Not that anybody should necessarily wait for that. My experience working with beast is very limited at the moment.

Tectu avatar Mar 26 '21 09:03 Tectu

The current code (on my end) is based on C++20 (could be easily down-graded to C++17). Does this even make for a useful example for you guys?

Tectu avatar Mar 30 '21 00:03 Tectu

Personally I think there is great value in a c++20 example. @vinniefalco I presume we'll also want to implement a c++11 version?

madmongo1 avatar Mar 30 '21 09:03 madmongo1

You have to use your best judgement. Try to follow the existing examples in terms of style. A C++20 example is okay (I assume because you want to use co_await). But in that case you also need a regular async/callback port of it. We can leave out the synchronous version :)

vinniefalco avatar Apr 07 '21 15:04 vinniefalco

Here is my "example" on how to use boost.beast: https://github.com/Tectu/malloy I might have digressed a bit. Maybe it's still worth listing it somewhere?

This is so far mainly the grunt work. It has many rough edges and needs serious improvements in several places.

I'd be thankful for any kind of feedback (or direct contributions!)

Tectu avatar Apr 29 '21 01:04 Tectu

The "example" has been released as v0.1.0: https://github.com/Tectu/malloy

Current feature list:

  • High-level controller to setup I/O context, SSL context, worker threads and more
  • HTTP
    • Plain or TLS (SSL) connections
    • Cookies
    • Sessions
    • Upgrading connections to WebSocket
    • Client
      • Response filters
    • Server
      • Routing
        • Simple handlers (useful for building REST APIs)
          • Target matching via regex
          • Capturing groups via regex
        • Sub-routers (nested/chained routers)
        • Redirections
        • File serving locations
        • Preflight responses
        • Access policies
          • HTTP basic auth
          • Custom access policies
        • Websocket endpoints (with auto-upgrade from HTTP)
      • Request filters
  • WebSocket
    • Client
    • Server
    • Connections upgradable from HTTP
  • HTML
    • Forms
      • Supported encoding types
        • application/x-www-form-urlencoded
        • multipart/form-data
        • text/plain
      • Parsing
      • Rendering

Feedback and contributions are highly welcomed.

Tectu avatar Aug 30 '21 17:08 Tectu

This is BIG !!

vinniefalco avatar Aug 30 '21 17:08 vinniefalco

This is more like a framework than an example

vinniefalco avatar Aug 30 '21 17:08 vinniefalco

This is more like a framework than an example

Hence I wrote "example" in quotation marks :p

No but seriously. This honestly started off as an example - I kid you not. I had several application using beast and a lot of the stuff was being repeated between applications. Putting this into a library/framework made sense (to me).

I will keep push this forward. I think that a fair share of beast users are dealing with lower level stuff they don't necessarily want to deal with but have to. I hope that this library will ease the pain and provide developers looking for a higher-level solution with a solid base built on top of beast.

You can definitely help out with a star ;p

Tectu avatar Aug 30 '21 17:08 Tectu

I was so caught up looking at the wonderful work you've gone that I forgot to Star, Like and smash that Subscribe button

vinniefalco avatar Aug 30 '21 18:08 vinniefalco

Haha ^^

So, do you think this is useful to you and other beast users? Should we point people towards this as an option for those who'd like to avoid the lower level stuff?

Tectu avatar Aug 30 '21 18:08 Tectu

I’d like to write a little application with it to give you some feedback.

madmongo1 avatar Aug 30 '21 20:08 madmongo1

Please do - that would be highly appreciated.

Tectu avatar Aug 30 '21 20:08 Tectu

New release is available: https://github.com/Tectu/malloy/releases/tag/0.3.0

Tectu avatar Jan 05 '22 19:01 Tectu

Seems like we're on the right track here, guys! Some feedback from a user & awesome contributor of malloy:

Serving a file with load balanced across multiple threads and asynchronous in less than 50 lines is damn impressive (its one of the reasons I started using and contributing to malloy, the router and client interfaces are really nice well done :p)

I think this approach of boost.beast being low level and malloy being higher level is gonna work out in everyone's favor! As such: Please keep up the good work guys!

Tectu avatar Jan 07 '22 14:01 Tectu

Wonderful.

madmongo1 avatar Jan 07 '22 14:01 madmongo1

@Tectu any progress to report?

klemens-morgenstern avatar Sep 24 '22 05:09 klemens-morgenstern

@Tectu any progress to report?

Yeah, lots of progress to report - anything specific you're interested in? I didn't report back here on each release as I didn't want to spam - but library developments are going well :)

The next release of malloy (0.6.0) is expected to land in the next few days. And probably most importantly: By now, malloy is being used successfully in a couple of real-world programs/software. There is also ongoing work for providing some higher-level interface to create REST APIs in the feature/rest branch. Hopefully, GraphQL will follow in the future as well. Of course, all of these things are optional to keep the core library as lean as possible.

Malloy is now also available as a package on FreeBSD. If somebody feels like creating packages for other operating systems (such as Ubuntu, Fedora, Arch, MacOS ...) that would be great :)

Tectu avatar Sep 24 '22 10:09 Tectu