Closed GuacheSuede closed 7 years ago
@lpereira
For the first question, you just have a URL map handler that matches "/hello/": making a request to "/hello/John" will call the appropriate handler. The URL in the request struct will be modified, having the "/hello/" prefix stripped, leaving only "John" in it.
For the second question, just add more mappings to the URL map.
Alright Thank you @lpereira , any plans to make a custom url params support eg. user/:id/posts
?
You can use the rewrite module and rewrite /user/(%a+)/(%a+)
to, say, /user_action?action=%2&user=%1
. Lwan provides functions to obtain variables passed to the query string.
@lpereira those are query params though, what about params part of string ?
If you use the rewrite module like that, requests to, say, "/user/John/display" will be rewritten so that "/user_action?action=display&user=John" is called instead. You could even have different handlers, for instance, so that Lwan will give a 404 for invalid actions:
rewrite /user/ {
pattern ^(%a+)/(%a+) { rewrite as = /user_%2?id=%1 }
}
&user_display /user_display
&user_delete /user_delete
(user_display
and user_delete
are handler functions.)
@lpereira Alright Thank You, final question if you dont mind, how do i specify diffrent GET/POST handlers for the route ?
The wiki is slightly outdated but there's a tutorial that might help you: https://github.com/lpereira/lwan/wiki/Using-Lwan-as-a-Library
@lpereira Yes I saw that, dint say how to specify different handler for routes, different GET/POST/DELETE /etc. handlers
You have only one handler per path. The handler has to dispatch based on the method (call lwan_request_get_method(), switch on REQUEST_METHOD_GET, ..._POST, ..._DELETE, etc).
I'm closing this issue as it wasn't really an issue to be fixed; feel free to reopen it, however.
Aight Sure, its fixed now, Thanks @lpereira
Hi Ipereira, how does one go about writing custom paths such as
/hello/John
and gettingJohn
as a param, and different paths leading to different handlers ?Thank You