Code Monkey home page Code Monkey logo

hng_stage_two's Introduction

HNG-Task2

This API allows you to perform CRUD (Create, Read, Update, Delete) operations on User Objects.

Prerequisites

Java 8 or higher Maven Postgresql 15

Installation

  1. Clone the repository to your local machine.

  2. git clone https://github.com/Alash95/hng_stage_two.git

  3. Run mvn clean install to build the project.

  4. Configure the application

The configuration for this API is stored in the application.properties file. To configure the API or make changes to its behavior, you can edit this file. Here's how:

  • Navigate to the directory where the application.properties file is located.

  • Open application.properties in a text editor of your choice.

  • Modify the configuration settings as needed. Common configurations include database connection details, server port, or API secret keys.

Example application.properties:

Database configuration

server.port = PORT
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=username
spring.datasource.password=password
  1. Package your application in a jar file using
mvn clean package
mvn install package
  1. Run the package by using the jar application file found in the target folder:

        java -jar your-application.jar
    

Endpoints

Create a User

  • Endpoint: POST
  • Description: Create a new user with a name and a value and email and value.
  • Request Body:
{
  "name": "John Doe",
  "email" : "[email protected]"
}
  • Response:
{
  "id": 1,
  "name": "John Doe",
  "email" : "[email protected]"
}

Get a Person by ID

  • Endpoint: GET /{user_id}
  • Description: Retrieve a user by their ID.
  • Response:
{
  "id": 1,
  "name": "John Doe",
  "email" : "[email protected]"
}

Update a Person by ID

  • Endpoint: PUT /{user_id}
  • Description: Update a user's name and value by their ID.
  • Request Body:
{
  "name": "new name",
  "email" : "new email"

}
  • Response:
{
  "name": "updated name",
  "email" : "updated email"
}

Delete a Person by ID

  • Endpoint: DELETE /{user_id}
  • Description: Delete a user by their ID.
  • Response:
{
  "message": "User deleted successfully"
}

Error Handling

  • If the provided ID does not exist, you will receive a 404 Not Found response.
  • If the provided email already exists, you will receive a "email already exists" response.
  • If the provided name is not a string, you will receive a "name must be a string" response.
  • If the provided email is not a string and in the wrong format, you will receive an "email must be a string" response.
  • If the request body does not contain valid name and value fields, you will receive a 400 Bad Request response.
  • If there is an internal server error, you will receive a 500 Internal Server Error response.

hng_stage_two's People

Contributors

alash95 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.