Skip to content

WackyDawg/HNGX-Backend-Project-2

Repository files navigation

wackydawg

Express CRUD API

A Node.js RESTful API Services with beautiful code written in JavaScript.
Inspired by the awesome framework Express.js in Node.js.
Made with ❤️ by Julian Nwadinobi(wackydawg)


divider

❯ Why

Our main goal with this project is to create a users CRUD system for the HNGX Internship Backend Track Task. Try it!! We are happy to hear your feedback or any kind of new features.

Features

divider

❯ Table of Contents

divider

❯ Getting Started

Step 1: Set up the Development Environment

You need to set up your development environment before you can do anything.

Install Node.js and NPM

Install yarn globally

yarn global add yarn

Step 2: Create new Project

Fork or download this project. Configure your package.json for your new project.

Then copy the .env.example file and rename it to .env. In this file you have to add your database connection information.

Create a new database with the name you have in your .env-file.

Then setup your application environment.

Go to the project dir and start your app with this yarn script.

yarn start serve

This starts a local server using nodemon, which will watch for any file changes and will restart the server according to these changes. The server address will be displayed to you as http://0.0.0.0:3000.

divider

Install

  • Install all dependencies with npm install

Tests

  • Run the e2e tests using npm test.

Running in dev mode

  • Run npm start to start nodemon with ts-node, to serve the app.
  • The server address will be displayed to you as http://0.0.0.0:3000

divider

❯ UML Diagram

wackydawg

## ❯ API Routes

The route prefix is /api by default, but you can change this in the .env file. The swagger and the monitor route can be altered in the .env file.

Route Description
/api When a POST request is made to this endpoint with the body parameter it inserts the data to the cloud servers.
/api/:userID Allowed request GET,PUT,DELETE

❯ Postman

Use Postman for testing the API. You can use any client :). So open postman and create a new post request to http://localhost:3000/api with this in the body

{
  "name": "Clark Kent"
}

create user using POST

POST /api

❯ POST Request Response

{
    "message": "Person created successfully🎉",
    "newPerson": {
        "_id": "6502152763bcef1970ba0a28",
        "name": "Clark Kent",
        "__v": 0
    }
}

divider

To make GET request

create a new Get request to http://localhost:3000/api/6502152763bcef1970ba0a28

GET /api/:user_id

get user using GET

❯ GET Request Response

{
    "Person": {
        "_id": "6502152763bcef1970ba0a28",
        "name": "Clark Kent",
        "__v": 0
    }
}

divider

To make PUT request

create a new PUT request to http://localhost:3000/api/64ff1ea91539022f0c4d1d98

PUT /api/:user_id

get user using GET

❯ PUT Request Response

{
    "message": "Successfully Updated",
    "updatedPerson": {
        "_id": "64ff1ea91539022f0c4d1d98",
        "name": "Julian Nwadinobi",
        "__v": 0
    }
}

divider

To make DELETE request

create a new DELETE request to http://localhost:3000/api/64ff1ea91539022f0c4d1d98

DELETE /api/:user_id

get user using GET

❯ DELETE Request Response

{
    "message": "User has been deleted successfully!🗑️"
}

divider

❯ Project Structure

Name Description
.vscode/ VSCode tasks, launch configuration, and other settings
controllers/ CRUD operations for managing user resources
coverage Validation rules for request bodies and code coverage
models Data models and response interfaces for user resources
node_modules * Custom type definitions and non-DefinitelyTyped files
router/ API routing for user-related endpoints
test/e2e/ *.test.js End-to-End tests for user creation and management
.env.example Example environment configuration settings
.env.test Test environment configuration settings
.gitignore Ignore file for version control
index.js Main application entry point
package-lock.json Dependency lock file for package consistency
package.json Project dependencies and configurations

divider

❯ Further Documentations

Name & Link Description
Express Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.
 Helmet Helmet helps you secure your Express apps by setting various HTTP headers. It’s not a silver bullet, but it can help! 
 Jest Delightful JavaScript Testing Library for unit and e2e tests 
 supertest Super-agent driven library for testing node.js HTTP servers using a fluent API 
 nock HTTP mocking and expectations library 
swagger Documentation   API Tool to describe and document your api.

divider

divider

❯ License

MIT

About

User CRUD API: A versatile API for creating, reading, updating, and deleting user profiles. Streamline user management in your applications with this comprehensive API solution.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors