It's a pure nodejs api using an express-like library I hacked out
- The
/lib
folder
The is the folder that holds the mini express-like library.
You can temper with it if you know what you are doing
- The
/src
folder
The is the folder that holds your api files which will be imported into index.js
This is all yours
- The
index.js
file
This is the file that starts your api.
This is all yours as well
- The
package.json
file
All the package.json is doing right now is helping to deploy to services like heroku.
Not for managing dependencies
- The
README.md
file
Contains clear documentation on how to go about things.
- Clone the repository
<https>: git clone https://github.com/mickeymond/pure-nodejs-api.git
<ssh>: git clone [email protected]:mickeymond/pure-nodejs-api.git
- cd into the project directory
cd pure-nodejs-api
- Start the Server
node index.js
- Use Postman or Browser to test
http://localhost:3000
- Start a NodeJS HTTP Server
const appServer = require('./lib');
const app = appServer();
- Register Routes with Handlers [GET, POST, PUT, DELETE]
app.get('/', (req, res) => {
// Business Logic goes here
// Return some JSON response
res.status(200).json({
message: "I really like what I am seeing"
});
});
- Application
app
app.listen(port<Number>, callback<Function>)
app.get(path<String>, handler<Function<req, res>>)
app.post(path<String>, handler<Function<req, res>>)
app.put(path<String>, handler<Function<req, res>>)
app.delete(path<String>, handler<Function<req, res>>)
- Request
req
req.params
req.query
req.body
- Response
res
res.json(response<Object>)
res.status(code<Number>)
- Get all EITS => GET /
Endpoint: http://localhost:3000 or https://pure-nodejs-api.herokuapp.com
Request: None
Response: Array of EITS
- Add an EIT => POST /
Endpoint: http://localhost:3000 or https://pure-nodejs-api.herokuapp.com
Request: {
"firstName": String|Required,
"lastName": String|Required,
"age": Number|Required,
"country": String|Required,
}
Response: Newly Added EIT
- Get an EIT => GET /id
Endpoint: http://localhost:3000/id or https://pure-nodejs-api.herokuapp.com/id
Request: None
Response: EIT with the provided id
- Update an EIT => PUT /id
Endpoint: http://localhost:3000/id or https://pure-nodejs-api.herokuapp.com/id
Request: {
"firstName": String|Optional,
"lastName": String|Optional,
"age": Number|Optional,
"country": String|Optional,
}
Response: Updated EIT
- Deleted an EIT => DELETE /id
Endpoint: http://localhost:3000/id or https://pure-nodejs-api.herokuapp.com/id
Request: None
Response: Deleted Success
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.