Git Product home page Git Product logo

sample-hapi-rest-api's Introduction

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: https://github.com/rcorral/hapi-restful-api-example

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 [email protected]:agendor/sample-hapi-rest-api.git
$ 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 database.sh:

$ chmod +x database.sh

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.sh

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.

sample-hapi-rest-api's People

Contributors

paulillo avatar tuliomonteazul avatar matemoln avatar bryant1410 avatar tlhunter 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.