Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
This branch is 2 commits behind agendor:master.

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

This project is outdated. We've built it with Hapi.js v3.0 and Node v0.10.26.
There is a another similar example working with newer versions here:

##Sample hapi.js REST API

A sample structure for building a REST API on top of hapi.js framework that consumes a MySQL database.

Start by cloning this repo and going inside the project's folder:

$ git clone
$ cd sample-hapi-rest-api

To begin with, we have to define some environment variables (with an Ubuntu 12.04 you can edit the ~/.bashrc file):

export NODE_ENV=development
export NODE_HOST=localhost
export NODE_PORT=8000
export DB_DEV_USER=root
export DB_DEV_PASS=rootpass

PS: Don't forget to alter DB_DEV_USER AND DB_DEV_PASS values properly to access your MySQL Database.

Then you have to give permission to the script

$ chmod +x

After giving permission, you can run it. It's going to drop and then re-create a MySQL Database called hapi-todo with user and task tables and insert a default user, which credentials are:

So run it:

$ bash

Database setup. So it's time to install project dependencies, run the following command:

$ npm install

Now you can check the recently created database in you MySQL. Start the server by running grunt in the terminal:

$ grunt

All the unit tests will run and everything should be green.

That's it! You should be able to play around your API GETting, POSTing, PUTing AND DELETEing Tasks. The end-points are as described in the src/routes/task.js file:

##Further reading

If you want a deeper analysis of the project, checkout this Gist.


A sample structure for building a REST API on top of hapi.js framework







No releases published


No packages published


  • JavaScript 95.4%
  • Shell 3.4%
  • Makefile 1.2%