This is a boilerplate for using Node.js with Express to host a RESTful API for a MySQL/MariaDB Database.
Supports Collection and Specific Item requests over GET, POST, PUT, DELETE (PATCH not currently implemented)
- Express (http://expressjs.com/en/4x/api.html)
- MySQL for Node (https://github.com/mysqljs/mysql)
- RESTAPI Tutorial (http://www.restapitutorial.com/lessons/httpmethods.html)
- Router in Express 4 (https://scotch.io/tutorials/learn-to-use-the-new-router-in-expressjs-4)
- Build a RESTful API Using Node and Express 4 (https://scotch.io/tutorials/build-a-restful-api-using-node-and-express-4)
- Node 404 (http://stackoverflow.com/a/33310600)
- RESTful Best Practices (http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#advanced-queries)
- Test a Node RESTful API with Mocha and Chai (https://scotch.io/tutorials/test-a-node-restful-api-with-mocha-and-chai)
- Express CORS (https://github.com/expressjs/cors)
-
npm install
-
create a
credentials.js
file in the root of the repomodule.exports = { host : 'localhost', user : 'me', password : 'secret', database : 'my_db' }
-
OR pass in MYSQL_HOST, etc as environment variables (eg. from Heroku's Config Vars)
-
Your database needs to be setup with a table called
panos
, feel free to use the included SQL, the only required field for the sake of this demo is theid
field. -
npm run start
to run server -
Use Postman or your browser to make requests to the api, at
/api/panoramas/
and/api/panoramas/:id
- Use whitelisted Origin header, instead of "*"
- Fix and Improve Route List Generation -
/api/
- Support for Filtering, Limiting, Sorting Results
- Architecture decision and Routes for how we handle Panorama Categories
- Authentication?
- Implement things from Consider Using Section