app.get()
Registers a route handling HTTP GET requests for a URL pattern.
Syntax
app.get(url, options?, handler) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
url | string | No | The route path, supporting :params and wildcards. |
options | RouteShorthandOptions | No | Optional schema, hooks, and config. |
handler | Function | No | Async handler receiving (request, reply). |
Returns
FastifyInstance — The instance, for chaining.
Examples
import Fastify from 'fastify';
const app = Fastify();
app.get<{ Params: { id: string } }>('/cats/:id', async (req) => {
return { id: req.params.id };
});
app.get(
'/health',
{ schema: { response: { 200: { type: 'object', properties: { ok: { type: 'boolean' } } } } } },
async () => ({ ok: true }),
);
Notes
Returning a value resolves the response automatically; you rarely need
reply.send(). Add a `schema` for request validation and faster response
serialization. Use TypeScript route generics for typed params and body.