Router
The router determines which handlers are called when a request hits the app based on HTTP method (GET, POST, DELETE, etc.) and URL. Every router handles routes a little differently so if you want to extend a router that already exists, it needs to meet the minimum requirements
- must support parameters in URL paths:
/music/{band}/{song}
- parameters in URLs must be surrounded in braces - if they use the convention where they start with a colon (
/music/:band/:song
), you can use theparamconvert
package to make it compatible with Ambient - must support routes being added and removed via
Clear(method string, path string)
- when plugins are disabled while the app is running, the routes must no longer be accessible - the order in which routes are added shouldn't matter. For instance, if
GET /app/{name}
is added beforeGET /app
, it should behave the same as if they were added in reverse
There are five routers in the library:
- awayrouter - routing using fork of
matryer/way
- chirouter - routing using
go-chi/chi
withparamconvert
- gorillamux - routing using
gorilla/mux
- jshttprouter routing using
julienschmidt/httprouter
withparamconvert
- patrouter - routing using
bmizerany/pat
withparamconvert
The awayrouter
is also used for the Dev Console.