Skip to content

DanieleFedeli/fastify-get-only

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastify-get-only

js-standard-style CI workflow

Plugin that make your fastify accepts only GET requests. It throws a 405 status code by default, but this can be changed via options.

Supports Fastify versions 3.x

Install

npm i fastify-get-only

Usage

Require\Import fastify-get-only and register.

// CommonJS
const fastify = require('fastify')();

fastify.register(require('fastify-get-only'), {
  httpStatusCode: 400 // Default is 405
  errorPayload: {
    whateverYouWant: "Method not allowed"
  }
});

// ESM
import Fastify from 'fastify';
import FastifyGetOnly from 'fastify-get-only';

fastify.register(FastifyGetOnly, {
  httpStatusCode: 400,
  errorPayload: {
    whateverYouWant: "Method not allowed"
  }
})

License

Licensed under MIT.