Questions tagged [hapijs]

Hapi is a rich Node.js framework for building web applications and services. It is a simple to use configuration-centric framework with built-in support for input validation, caching, authentication, and other essential facilities.

Hapi is a rich Node.js framework for building web applications and services. It is a simple to use configuration-centric framework with built-in support for input validation, caching, authentication, and other essential facilities.


Community


Other useful links

1257 questions
136
votes
6 answers

How do Express and hapi compare to each other?

From web application design and development point of view, how do Express and Hapi compare to each other? For basic examples they seem similar, however I'm interested to learn more about key differences in overall application structure. For example,…
Ali Shakiba
  • 18,573
  • 17
  • 59
  • 86
86
votes
6 answers

How to destroy JWT Tokens on logout?

I am using jwt plugin and strategy in hapijs. I am able to create jwt token while login user and authenticate other API using the same token through 'jwt' strategy. I am setting the token in request.state.USER_SESSION as a cookie where USER_SESSION…
Garima
  • 1,016
  • 1
  • 8
  • 13
69
votes
7 answers

Joi validation of array

trying to validate that an array has zero or more strings in one case and that it has zero or more objects in another , struggling with Joi docs :( validate: { headers: Joi.object({ 'content-type':…
1977
  • 1,697
  • 2
  • 20
  • 25
59
votes
7 answers

How to store routes in separate files when using Hapi?

All of the Hapi examples (and similar in Express) shows routes are defined in the starting file: var Hapi = require('hapi'); var server = new Hapi.Server(); server.connection({ port: 8000 }); server.route({ method: 'GET', path: '/', handler:…
Centurion
  • 13,168
  • 31
  • 99
  • 189
35
votes
2 answers

How to allow any other key in Joi

I have a simple requirement. I tried to search on the internet as well as documentation but failed. So here is what I want to achieve: I have a schema: const schema = Joi.object().keys({ a: Joi.string().required(), b:…
Anand Undavia
  • 2,985
  • 4
  • 14
  • 31
33
votes
4 answers

Joi validation return only one error message

I have a three field form made of a name field, email field and a textarea. I'm using Joi 4.7.0 version along with hapijs. I use the object below validate the input. I receive the data object from an ajax call. When I fill all the three fields with…
Mazzy
  • 11,255
  • 34
  • 110
  • 179
26
votes
2 answers

Joi validation multiple conditions

I have the following schema: var testSchema = Joi.object().keys({ a: Joi.string(), b: Joi.string(), c: Joi.string().when('a', {'is': 'avalue', then: Joi.string().required()}) }); but I would like to add a condition on c field…
user2468170
  • 974
  • 2
  • 12
  • 18
23
votes
1 answer

Joi object validation: How to validate values with unknown key names?

I have an object with key names I cannot possibly know - they are created by user. However I do know what values they (keys) are going to store, and they (values) are going to be ISO strings. How do I validate those values? And, optionally, how do I…
wscourge
  • 8,047
  • 10
  • 43
  • 66
21
votes
3 answers

Using Joi, require one of two fields to be non empty

If I have two fields, I'd just like to validate when at least one field is a non empty string, but fail when both fields are empty strings. Something like this does not validate var schema = Joi.object().keys({ a: Joi.string(), b:…
Brendan
  • 579
  • 1
  • 5
  • 12
20
votes
2 answers

Multipart HTTP response

The goal is for a Node.js / hapi API server to respond to a browser's AJAX request with two things: A media file (e.g. an image) A JSON object with metadata about the file These are two separate items only because binary data cannot easily be…
Seth Holladay
  • 6,356
  • 2
  • 23
  • 38
20
votes
3 answers

How to log all requests made to a hapi server without using a logging library?

I'd like to see a nice log with short info about each request to my server, for use during development. I've seen the documentation on http://hapijs.com/api#request-logs, but I couldn't understand enough of it to get it working. What should I pass…
mik01aj
  • 10,150
  • 11
  • 65
  • 109
19
votes
3 answers

Hapi nested routing

Suppose I want to have REST endpoints which look roughly like this: /projects/ /projects/project_id /projects/project_id/items/ /projects/project_id/items/item_id CRUD on each if makes sense. For example, /projects POST creates a new project, GET…
PoMaHTuK
  • 213
  • 2
  • 7
18
votes
3 answers

How should I use Swagger with Hapi?

I have a working ordinary Hapi application that I'm planning to migrate to Swagger. I installed swagger-node using the official instructions, and chose Hapi when executing 'swagger project create'. However, I'm now confused because there seem to be…
Kitanotori
  • 1,531
  • 3
  • 14
  • 22
18
votes
4 answers

How to get the full URL for a request in Hapi

In my hapijs app, given a Request object, how can I find the original, unparsed, unmodified URL? function getRequestUrl (request) { return ...; // What goes here? } I've found that I can piece it together somewhat from Request.info.host,…
gilly3
  • 78,870
  • 23
  • 132
  • 169
17
votes
3 answers

How to upload files using nodejs and HAPI?

Can anyone tell me How to upload files Using nodejs and HAPI? I am getting binary data inside the handler. Here is my html code: function sendFormFromHTML(form) { //form = $(".uploadForm").form; var formData = new FormData(form); …
Realdheeraj
  • 349
  • 1
  • 2
  • 9
1
2 3
83 84