You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current routing mechanism in Yap, exemplified by file names like get_p_#id.yap, effectively maps a single HTTP method to a specific route, e.g., GET /p/:id. However, this approach presents limitations when one wishes to register multiple HTTP methods for the same route or utilize a wildcard to match any method for a given route. This proposal aims to extend the current routing syntax to accommodate these use cases.
Proposed enhancements
Support for multiple methods: To allow multiple methods to be associated with a single route, I propose a syntax where methods are concatenated using a , sign. For instance, get,head_p_#id.yap would register the /p/:id route for both GET and HEAD methods.
Wildcard method support: To enable a route to respond to any HTTP method, I propose the use of an * prefix. For example, *_p_#id.yap would match the /p/:id route for any HTTP method. This would replace the existing but less intuitive handle_p_#id.yap, aligning with the more recognized wildcard symbol *. (HANDLE is not a standard HTTP method, but non-standard methods are allowed in the HTTP spec, e.g., WebDAV uses many non-standard methods.)
Conflict resolution
In cases where multiple files might match a request (e.g., *_p_#id.yap and get_p_#id.yap), the router should prioritize the more specific match. Therefore, a GET /p/:id request would be handled by get_p_#id.yap over *_p_#id.yap, given the explicit mention of the GET method in the former.
Rationale
Flexibility: This enhancement would offer developers greater flexibility in defining their APIs, allowing for more concise and powerful routing configurations.
Convenience: By supporting multiple methods in a single route definition, we reduce redundancy and make route management more straightforward.
Conclusion
I believe these enhancements will make Yap more powerful and flexible, catering to a broader range of routing requirements.
The text was updated successfully, but these errors were encountered:
For the support of multi-method syntax, there's a workaround worth mentioning. One can avoid duplicating the same .yap files for different methods by utilizing symbolic links.
For example:
$ gop mod init hello
$ gop get github.com/goplus/yap@latest
$ echo 'html `<html><body>Hello, YAP!</body></html>`' > get.yap
$ ln -s get.yap head.yap
$ gop mod tidy
$ gop run .
$ curl -i localhost:8080
HTTP/1.1 200 OK
Content-Length: 37
Content-Type: text/html
Date: Mon, 11 Mar 2024 07:53:23 GMT
<html><body>Hello, YAP!</body></html>
$ curl -I localhost:8080
HTTP/1.1 200 OK
Content-Length: 37
Content-Type: text/html
Date: Mon, 11 Mar 2024 07:53:26 GMT
Introduction
The current routing mechanism in Yap, exemplified by file names like
get_p_#id.yap
, effectively maps a single HTTP method to a specific route, e.g.,GET /p/:id
. However, this approach presents limitations when one wishes to register multiple HTTP methods for the same route or utilize a wildcard to match any method for a given route. This proposal aims to extend the current routing syntax to accommodate these use cases.Proposed enhancements
,
sign. For instance,get,head_p_#id.yap
would register the/p/:id
route for bothGET
andHEAD
methods.*
prefix. For example,*_p_#id.yap
would match the/p/:id
route for any HTTP method. This would replace the existing but less intuitivehandle_p_#id.yap
, aligning with the more recognized wildcard symbol*
. (HANDLE
is not a standard HTTP method, but non-standard methods are allowed in the HTTP spec, e.g., WebDAV uses many non-standard methods.)Conflict resolution
In cases where multiple files might match a request (e.g.,
*_p_#id.yap
andget_p_#id.yap
), the router should prioritize the more specific match. Therefore, aGET /p/:id
request would be handled byget_p_#id.yap
over*_p_#id.yap
, given the explicit mention of theGET
method in the former.Rationale
Conclusion
I believe these enhancements will make Yap more powerful and flexible, catering to a broader range of routing requirements.
The text was updated successfully, but these errors were encountered: