httpswift / swifter

Tiny http server engine written in Swift programming language.
BSD 3-Clause "New" or "Revised" License
3.9k stars 539 forks source link

Async handling; Controller protocol; Path/handler conveniences #526

Open namolnad opened 2 years ago

namolnad commented 2 years ago

Hi there 👋

This PR is mostly to gauge interest in a few changes I've made to a forked copy of this package. I can very easily split this up into many PRs if there is interest in any/all of this, but first wanted to see how it was received. Thanks for having a look!

Included Changes

  1. Support Async/Await a. Allows use of async/await to make async extremely simple
  2. Fix file dir handling a. Noticed files within directories were broken
  3. Exclude DemoServer from package a. Slim out the package
  4. Add controller protocol and convenience subscript a. Allows GET["your/route"] = MyController.myRouteHandler i. The above would be possible for the following: struct MyController: Controller { func myRouteHandler(_ request: HttpRequest) async -> HttpResponse {
  5. Enable registering multiple paths for a given handler a. Allows GET["my/first/route", "my_other_route"] = { request in }
  6. Trim : from request parameters a. Allows request["parameterName"] vs request[":parameterName"] as a more convenient/intuitive accessor. i. Addresses #489
namolnad commented 2 years ago

(Worth noting there are some CI issues and OS version items that will need to be sorted out if these changes are desirable for others besides myself)