Skip to content

Conversation

lionhylra
Copy link

Create a function to enable add batch handlers.
Use case:

server.appendRoutes([
            "/fish/accepted" => ClosureHTTPHandler { _ in
                HTTPResponse.make(statusCode: .accepted)
            },
            "/fish/*" => .file(named: "fish.json", in: .module)
        ])

@codecov
Copy link

codecov bot commented Feb 28, 2022

Codecov Report

Merging #7 (64134b0) into main (e103d82) will increase coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main       #7      +/-   ##
==========================================
+ Coverage   89.60%   89.68%   +0.08%     
==========================================
  Files          29       29              
  Lines        1087     1096       +9     
==========================================
+ Hits          974      983       +9     
  Misses        113      113              
Impacted Files Coverage Δ
Sources/HTTPServer.swift 94.61% <100.00%> (+0.26%) ⬆️
Sources/Handlers/RoutedHTTPHandler.swift 66.66% <100.00%> (+3.70%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e103d82...64134b0. Read the comment docs.

@lionhylra
Copy link
Author

There is a concern for this PR. This library defines a custom operator "=>", if a project that defining same operator or imports a library that defines same operator, there could be conflicts.

@lionhylra
Copy link
Author

Verified that defining custom operators in both project and library won't cause conflicts. They are just like method overloads.

@swhitty
Copy link
Owner

swhitty commented Mar 1, 2022

Thanks for you PR @lionhylra. It is an interesting idea and we should think about it.

IMO the operator => is clear but I am unsure how common it is, and maybe a label verb to: is just as concise.

The existing syntax is OK;
.appendRoute("/fish/*", to: .file(named: "fish.json", in: .module))

I know we have had discussions offline about how we could possible use a @resultBuilder to declare these things — It would be interesting to see what the limitations of that approach is.

@lionhylra
Copy link
Author

Thanks for you PR @lionhylra. It is an interesting idea and we should think about it.

IMO the operator => is clear but I am unsure how common it is, and maybe a label verb to: is just as concise.

The existing syntax is OK; .appendRoute("/fish/*", to: .file(named: "fish.json", in: .module))

I know we have had discussions offline about how we could possible use a @resultBuilder to declare these things — It would be interesting to see what the limitations of that approach is.

I kind of agree. Personally I think word expression is always better than operator, like you said using verb label to. Adding operator "=>" is something nice to have to allow users to make nice router mappings, but it is not required in library.
I also think resultBuilder is not suitable for this use case and it's overkill.

@swhitty swhitty closed this Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants