GithubHelp home page GithubHelp logo

thegodhope / hng-backend-task2 Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 299 KB

A simple CRUD app for managing persons

Home Page: https://hng-backend-task2-idorenyin.vercel.app/

JavaScript 100.00%

hng-backend-task2's Introduction

HNG STAGETWO BACKEND TASK

A Simple CRUD operation API for managing Persons

TABLE OF CONTENTS

  • Introduction
  • Features
  • Requirements
  • Getting Started
  • API Endpoints
  • Error Handling
  • Usage
  • UML Diagram
  • Testing
  • Documentation

Introduction

This project is a simple REST API for managing persons. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on person resources. The API is built using Node.js and MongoDB, and it provides a flexible way to handle dynamic parameters, such as adding or retrieving a person by name.

Features

  • Create, Read, Update, and Delete items.
  • RESTful API endpoints.
  • Simple and easy-to-understand codebase.

Requirements

  • Node.js and npm installed on your machine.
  • Postman (for testing)

Getting Started

  1. Clone this repository to your local machine:

     git clone https://github.com/thegodhope/hng-backend-task2.git
    
    
  2. Navigate to the project directory:

    cd <"your_cloned_location">/hng_backend_task2
  3. Install packages using

    npm install
  4. Start the server, use the following command: npm start The API will be accessible at http://localhost:8000

API Endpoints

  • GET /api : run api health check
  • POST /api : Create a new person
  • GET /api/:id: Fetch details of a person by ID
  • PUT /api/:id : Update details of an existing person by ID
  • DELETE /api/:id: Remove a person by ID

Error Handling

When using the API, you may encounter various error responses. Below are some common error scenarios and their corresponding HTTP status codes:

  • 400 Bad Request: This status code is returned when the request is malformed or missing required parameters. Check your request payload and ensure it follows the API's expected format.

  • 404 Not Found: When trying to access a resource that does not exist, the API responds with a 404 status code. Double-check the resource's ID or name provided in the request.

  • 409 Conflict: If you attempt to create a resource that already exists, such as a person with the same name, the API will return a 409 status code. Ensure the resource is unique or consider updating the existing one.

  • 500 Internal Server Error: In case of unexpected server errors, you might receive a 500 status code. If you encounter this, it's recommended to report the issue to me at here.

Usage

  1. Use an API testing tool like Postman or Curl to interact with the API endpoints.

Sample Usage

  • Create User -Request :
post /api
content-Type: application/json

{
    "name": "idorenyin"
}
  • Create User -Response :
post /api
status: 200

{
   "message" : "user created successfully",
    "result" : {
      "name" : "idorenyin",
      "_id": "1",
      "__v": 0
    }
}

UML DIAGRAM

Alt text

DOCUMENTATION

Alt text

Visit here for full API documentation

  • Testing

You can test the API using Postman. Use the provided Postman collection for testing CRUD operations.

Click to test on Postman

API Url

https://hng-backend-task2-idorenyin.vercel.app/api

hng-backend-task2's People

Contributors

thegodhope avatar

Watchers

 avatar

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.