https://github.com/olistic/hapi-overriding
Override HTTP verbs
https://github.com/olistic/hapi-overriding
Last synced: about 2 months ago
JSON representation
Override HTTP verbs
- Host: GitHub
- URL: https://github.com/olistic/hapi-overriding
- Owner: olistic
- License: mit
- Created: 2015-04-02T04:09:14.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-05-14T02:52:05.000Z (about 11 years ago)
- Last Synced: 2025-12-26T15:10:14.005Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 180 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hapi-overriding
**hapi-overriding** is a [hapi](https://github.com/hapijs/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](https://github.com/ubaltaci/hapi-method-override).
[](https://travis-ci.org/olistic/hapi-overriding)
[](https://coveralls.io/r/moliveraf/hapi-overriding?branch=master)
## Install
```sh
$ 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:
```html
Delete user
```
Server-side:
```javascript
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`.