Giter Site home page Giter Site logo

hapi-overriding's Introduction

hapi-overriding

hapi-overriding is a hapi plugin that allows you to override the method of an incoming request, using HTTP verbs such as PUT and DELETE in places where the client doesn't support it. This package was inspired in hapi-method-override.

Build Status Coverage Status

Install

$ npm install hapi-overriding

Usage

hapi-overriding works by extending the onRequest step of the request lifecycle. The extension function checks, for any incoming POST request, if the path ends with one of the defined action names (e.g. destroy). If so, it will change the method to the corresponding HTTP verb (e.g. DELETE). It will also change the url of the request, removing the action part and keeping your routes clean.

Example

Client-side:

<form method="POST" action="/users/507f1f77bcf86cd799439011/destroy">
  <button type="submit">Delete user</button>
</form>

Server-side:

var Hapi = require('hapi');
var server = new Hapi.Server();

server.connection({ port: 3000 });

server.register(require('hapi-overriding'), function(err) {

  if (err) {
    throw err;
  }

  server.route({
    method: 'DELETE',
    path: '/users/{id}',    // No `/destroy` at the end!
    handler: function (request, reply) { ... }
  });

  server.start();
});

Options

The action names may be customized by passing the following options when registering the plugin:

  • put - the action that represents the PUT verb. Defaults to update.
  • delete - the action that represents the DELETE verb. Defaults to destroy.

hapi-overriding's People

Contributors

olistic avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.