Comments (8)
I like this idea. I'd like to continue to support the current interface, though. I think the async response is less common.
Possibly a Route.getAsync()
or Route.get().async()
API would work.
from vapor.
It should be possible to support both, without having different interfaces defined, using function overloading.
// Sync
Router.post("") { request in
return Response()
}
// Async
Router.post("") { request, response in
response.send()
}
from vapor.
I'm not at a computer right now to see if Swift would complain about the params to the closure not matching. But I know it will complain if the closure doesn't return a Response
..
Possibly an AsyncResponse
object could be returned with a closure inside.
from vapor.
@elliottminns Just saw the note about function overloading. You're right. I think that would work.
from vapor.
Awesome, I'll get started on this on my fork.
from vapor.
I've managed to implement this however with one caveat. I get this build error for using my old sync methods now, such as
Route.get("/") { request in
let view = try View(path: "Views/index.html")
return view
}
/Project/Sources/main.swift:9:1: error: ambiguous use of 'get(_:closure:)'
Route.get("/") { request in
^
Vapor.Route:4:23: note: found this candidate
public class func get(path: String, closure: Vapor.Route.Type.Closure)
^
Vapor.Route:5:23: note: found this candidate
public class func get(path: String, closure: Vapor.Route.Type.ResponseClosure)
^
<unknown>:0: error: build had 1 command failures
It seems that while the async method works fine, the interface for the sync method is now too ambiguous for the compiler. This can be solved by explicitly defined which closure type it is, however this does take away from the cleanliness of the original interface and will be breaking for any current code:
Route.get("/") { (request) -> ResponseConvertible in
let view = try View(path: "Views/index.html")
return view
}
It may be cleaner therefore to instead add a Route.async.get()
or Route.getAsync()
method instead to preserve the original interface.
Let me know your thoughts
from vapor.
Can you create a pull request with the changes?
from vapor.
6b033df fixes this.
from vapor.
Related Issues (20)
- Query decoding broken in 4.90 HOT 3
- vapor and toolbox compile error on arch linux HOT 1
- double slash in URL no longer matches route handlers HOT 3
- URI semantics are broken HOT 1
- commùit
- Double slash in URLs still breaks route matching with variable parts in vapor 4.92.0 HOT 2
- Trying to build on Ubuntu 20 with swift run and getting Building for debugging... error: emit-module command failed due to signal 9 HOT 2
- Unable to shutdown server HOT 1
- Title
- Vapor URLQueryContainer no longer supports valueless query parameters HOT 4
- Swift Vapor-Save records in Mysql JSON data type during mapping with swift get error- Could not convert MySQL data to String: <MYSQL_TYPE_JSON HOT 6
- Large, streamed request body may result in noSignalReceived preconditionFailure crash HOT 6
- Websocket shouldUpgrade() fail causes empty reply from server HOT 4
- Cannot setup a route returning `[Int: String]` HOT 7
- Log actual port when it's picked by the OS
- 'Flag' URL Query params don't decode into structs HOT 3
- HEAD response should allow non-zero Content-Length HOT 2
- Authentication Cache + Storage crash application HOT 2
- Default to `HTTPClient.shared` when possible HOT 1
- URLFormEncoder does not escape all reserved characters HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vapor.