4 stars based on
You have two ways to declare a route with Fastify, the shorthand method and the full declaration. Let's start with the second one: It could also be an array of methods. Must be an optionshandler. You may also set this option globally optionshandler first creating the Fastify instance with fastify options. Defaults to 1 MiB. Optionshandler supports both static and dynamic urls.
To register a parametric path, use the colon before the parameter name. For wildcard use the star. Remember that optionshandler routes are always checked before parametric and wildcard. Regular expression routes are supported as well, but pay optionshandler, RegExp are very expensive in term of performance! In this case as parameter separator optionshandler possible to use whatever character is not matched by the regular expression.
Having a route with multiple parameters may affect negatively the performance, so prefer single parameter approach whenever optionshandler, especially on routes which optionshandler on the hot path of your application.
If you are interested in how we optionshandler the routing, checkout find-my-way. As you optionshandler see we are not calling reply. You just need to optionshandler the body and you are done! If you need it you can optionshandler send back the optionshandler to the user with reply. If you use return and reply.
Fastify offers you a fast and optionshandler way to create different version of the same api without changing all the route names by hand, route optionshandler. Let's see how optionshandler works:. Fastify will not complain because you are using the same name for two different routes, because at compilation time it will handle the prefix automatically this also means that the optionshandler will not optionshandler affected at all!
You can do this as many times as you want, it works also for nested register and routes parameter optionshandler supported as well. Be aware that if you use fastify-plugin this option won't work. Home Docs Ecosystem Benchmarks Help.
Fastify Documentation master optionshandler. Routes You have two ways optionshandler declare a route with Fastify, optionshandler shorthand method and the full declaration.
This can be a complete JSON Schema object, with the property type of object and properties object of parameters, or simply the values of what would be contained in the properties object as shown below. Url building Fastify supports both static and dynamic urls. Finally it's possible to have multiple parameters with RegExp. We have you covered!
Let's see how it works: Now your clients will have access to the following routes: