Prompt
When implementing integrations and plugins using the Fastify framework, maintain consistent coding patterns and conventions:
- Follow Fastify’s recommended package naming conventions, using the
@fastifyscope for all Fastify-specific packages (e.g.@fastify/kafkainstead offastify-kafka). - Ensure integrations provide clear and comprehensive documentation of the specific protocol, system or service being integrated (e.g. “Plugin to interact with Apache Kafka message broker”).
- Use Fastify’s built-in type definitions and decorators consistently across all plugins and integrations.
- When referencing external protocol standards, include the full RFC reference with a period at the end of the description (e.g. “Plugin to add HTTP 103 Early Hints based on RFC 8297.”).
Example Fastify integration:
import fastify, { FastifyInstance } from 'fastify';
import { FastifyKafka } from '@fastify/kafka';
const server: FastifyInstance = fastify();
server.register(FastifyKafka, {
brokers: ['kafka1:9092', 'kafka2:9092'],
topic: 'my-topic'
});
server.get('/messages', async (request, reply) => {
const messages = await server.kafka.consume();
return messages;
});
Consistent implementation of Fastify integrations and plugins improves maintainability, makes resources easier to discover, and ensures developers can quickly understand the purpose and usage of network-related features in Fastify applications.