Giter VIP home page Giter VIP logo

api's Introduction

Sample hapi REST Api server

Self teaching hapi

What it does

  • query postgres for existing databases http://localhost:8000/databases
  • uses winston for logging
  • log output seperated by module (auth, routes, db, logger)
  • basic authentication on http://localhost:8000/login to receive a cookie
  • provides a route http://localhost:8000/hello/{id} available after cookie was received
  • replys with hello id: 42 where 42 ist the {id}
  • uses swagger for api documentation http://localhost:8000/documentation
  • uses joi to verify parameters
  • seperates routes in a file /modules/routes.js
  • seperates plugin in a file /pugins/plugins.js
  • swagger documentation grouped by tag
  • user enviroment variables for configuration (see set_env.sh)

What is missing (ToDo)

  • seperate handlers from routes
  • more routes
  • authentication
  • routes with and without authentication
  • using https (because its 2017!)
  • database example
  • automated testing
  • nginx as loadbalancer not part of the app
  • example for multiple instances can be handled elswhere (nginx, kubernetes)
  • jwt integration

Installing

  1. Install node
  2. git clone https://github.com/holymoly/api
  3. cd api && npm install
  4. node app.js
  5. Open http://localhost:8000/login in your browser
  6. Open http://localhost:8000/hello/42 in your browser
  7. Open http://localhost:8000/documentation in your browser

Build the Testenviroment

docker pull rabbitmq
docker run -d --hostname api-test --name api-test -e RABBITMQ_DEFAULT_USER=test -e RABBITMQ_DEFAULT_PASS=test -p 8080:15672 -p 1883:1883 rabbitmq:3-management
docker exec -it api-test /bin/bash
rabbitmq-plugins enable rabbitmq_mqtt
exit
2. ```
  docker run -d --name some-postgres -e POSTGRES_PASSWORD=test -p 5432:5432  postgres

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.