GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - felipeleusin/hapi-negotiator: Integrates Hapi with Negotiator

BranchesTags
Open more actions menu

Latest commit

 

History

22 Commits
22 Commits

Folders and files

NameName
Last commit message
Last commit date
lib
lib
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
index.js
index.js
 
 
package.json
package.json
 
 

Repository files navigation

Hapi Content Negotiation

Build Status Dependency Status

Hapi Content Negotiation Plugin

This project enhances content negotiation capabilities of Hapi. It's a wrapper around Negotiator module.

Purpose

When you have the same route but wants it to respond json or a html view depending on the Accept header.

Options

The plugin supports the following options:

  • mediaTypes - (optional) a object containing a combination of global media types where the key is the media type name and the value is one of the following:
    • function (request, reply) - the function is called receiving the request and the reply
    • true - perform the default reply(). Effective no-op.
    • false - throws Boom.notAccepted() error
    • { method, args } - invoke the method on the reply method passing an args array. The args array is appended the default reply object.

Example

You have to configure the plugin for each route, so if you want a route to respond with a view named index when accept is text/html, notAccepted when image/jpeg and the regular json reply when application/vnd.project+json you should configure it as

server.route({
	method: 'GET',
	path: '/',
	config: {
		plugins: {
			'hapi-negotiator': {
				mediaTypes: {
					'text/html': { method: 'view', args: ['index'] },
					'image/jpeg': false,
					'application/vnd.project+json': true,
				}
			}
		}
	}
});

Todo

  • Improve documentation
  • Include negotiation for Accept Language. Maybe combine with one of the localization modules?

Comments/Suggestions

Feel free to open an issue.

About

Integrates Hapi with Negotiator

Resources

Readme
MIT license
Activity

Stars

11 stars

Watchers

0 watching

Forks

4 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.