Example project for API creation using NodeJS
Tech stack
- sqlite3
- nodejs (see dependencies in package.js), but mainly uses express to serve content
The table is created with the following command.
CREATE TABLE users (id integer PRIMARY KEY AUTOINCREMENT, name varchar(20) NOT NULL, password varchar(20) NOT NULL, profession varchar(20));
Supported end-point is as follows
-
/listUsers
GET
method
Get list of users. -
/addUser
POST
method
Add a new user with following parameters specParam Name Type Required name varchar(20) YES password varchar(20) YES profession varchar(20) NO -
/:id
GET
method
Get detail of specific user from:id
. -
/deleteUser
POST
method
Delete a user from id.
- Start server instance (
index.js
of this project) by executingnode index.js
. - Make a client request from either Postman, cURL, or Javascript code.
Please note that you need to know your API URL (server instance that is listening) which depends on your setup.
- Good starting point to follow to build up database structure, and overview approach using NodeJS API https://www.tutorialspoint.com/nodejs/nodejs_restful_api.htm
- sqlite3 on Github
- Tutorial on using expressjs to get GET/POST parameters
Project is licensed under MIT.