From 57b093c4c2578e950fb2ac37e88c08f687f22309 Mon Sep 17 00:00:00 2001 From: Simon Gurcke Date: Mon, 22 Jan 2024 13:06:47 +1000 Subject: [PATCH] Update README --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c2e381..a131d19 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ This is an example of how to register the Apitally plugin with a Fastify application. For further instructions, see our [setup guide for Fastify](https://docs.apitally.io/frameworks/fastify). -_Note:_ The Apitally plugin requires the +The Apitally plugin requires the [`fastify-plugin`](https://www.npmjs.com/package/fastify-plugin) package to be installed. @@ -121,12 +121,22 @@ npm install fastify-plugin const fastify = require("fastify")({ logger: true }); const { apitallyPlugin } = require("apitally/fastify"); -await fastify.register(apitallyPlugin, { +fastify.register(apitallyPlugin, { clientId: "your-client-id", env: "dev", // or "prod" etc. }); + +// Wrap your routes in a plugin, so Apitally can detect them +fastify.register((instance, opts, done) => { + instance.get("/", (request, reply) => { + reply.send("hello"); + }); + done(); +}); ``` +_Note:_ If your project uses ES modules you can use `await fastify.register(...)` and don't need to wrap your routes in a plugin. See the [Fastify V4 migration guide](https://fastify.dev/docs/latest/Guides/Migration-Guide-V4/#synchronous-route-definitions-2954) for more details. + ### Koa This is an example of how to use the Apitally middleware with a Koa application.