Code Monkey home page Code Monkey logo

restpanda's Introduction

Homepage

Site Link

Steps to setup

Install nodejs from here

Install mongodb by following the instructions given on this link

Install npm dependencies

npm install

Start employees api:

npm run employees

Start newSalary api:

npm run newSalary

APIs

The below sections outlines the Sequence Diagram & Details around the APIs

SequenceDiagram

api_sequence_diagram

Details

This section outlines the details of the below 2 APIs:

employees

The employees API can be used to create/store employee information. It contains the following Routes:

  • /employees
  • /employees/:employeeName

/employees

Methods Supported are POST and GET

POST

Use this method to add new employee(s) to the DB. This example shows usage of Body and Optional Field (Gender) in the request.

Body
Field Data Type Required Example
employeeName String true user001
emailId String true [email protected]
gender String false female
title String true manager
currentSalary Number true 80000
Sample Curl Request...

curl --location --request POST 'http://localhost:3000/employees' \
--header 'Content-Type: application/json' \
--data-raw '[{
    "employeeName": "user001",
    "emailId": "[email protected]",
    "gender": "female",
    "title": "manager",
    "currentSalary": "80000"
}, {
    "employeeName": "user002",
    "emailId": "[email protected]",
    "gender": "female",
    "title": "director",
    "currentSalary": "80000"
}]'

Sample Response Body...

[
    {
        "message": "user001 employee created"
    },
    {
        "message": "user002 employee created"
    }
]

GET

Use this method to get information of all the employees available in the DB. This example simply shows how GET Method is being used to fetch multiple records.

Sample Curl Request...

curl --location --request GET 'http://localhost:3000/employees' \
--header 'Content-Type: application/json'

Sample Response Body...

[
    {
        "_id": "5e7115d803b7cc50f8f93863",
        "employeeName": "user001",
        "emailId": "[email protected]",
        "gender": "80000",
        "title": "manager",
        "currentSalary": 80000,
        "createdAt": "2020-03-17T18:24:24.365Z",
        "updatedAt": "2020-03-17T18:24:24.365Z",
        "__v": 0
    },
        {
        "_id": "5e7115d803b7cc50f8f93863",
        "employeeName": "user002",
        "emailId": "[email protected]",
        "gender": "male",
        "title": "engineer",
        "currentSalary": 60000,
        "createdAt": "2020-03-17T18:17:24.365Z",
        "updatedAt": "2020-03-17T18:17:24.365Z",
        "__v": 0
    },

]

/employees/:employeeName

Methods Supported are GET, PUT and GET

GET

Use this method to get the information of an employee. This example shows usage of Path Parameter & Query Parameter (API response delay time in seconds) in the request.

Path Parameter
Field Data Type Required Example
employeeName String true user001
Query Parameter
Field Data Type Required Example
delay Number false 4
Sample Curl Request...

curl --location --request GET 'http://localhost:3000/employees/user001?delay=4' \
--header 'Content-Type: application/json'

Sample Response Body...

{
    "_id": "5e7115d803b7cc50f8f93863",
    "employeeName": "user001",
    "emailId": "[email protected]",
    "gender": "female",
    "title": "manager",
    "currentSalary": 80000,
    "createdAt": "2020-03-17T18:24:24.365Z",
    "updatedAt": "2020-03-17T18:24:24.365Z",
    "__v": 0
}

PUT

Use this method to update the information of an employee. This example shows usage of Body & Path Parameter in the request.

Path Parameter
Field Data Type Required Example
employeeName String true user001
Body
Field Data Type Required Example
employeeName String true user001
emailId String true [email protected]
gender String false female
title String true manager
currentSalary Number true 80000
Sample Curl Request...

curl --location --request PUT 'http://localhost:3000/employees/user001' \
--header 'Content-Type: application/json' \
--data-raw '{
    "employeeName": "user001",
    "emailId": "[email protected]",
    "gender": "female",
    "title": "director",
    "currentSalary": 100000
}'

Sample Response Body...

{
    "_id": "5e7115d803b7cc50f8f93863",
    "employeeName": "user001",
    "emailId": "[email protected]",
    "gender": "female",
    "title": "director",
    "currentSalary": 100000,
    "createdAt": "2020-03-17T18:24:24.365Z",
    "updatedAt": "2020-03-20T20:50:03.590Z",
    "__v": 0
}

DELETE

Use this method to delete the information of an employee. This example shows usage of Path Parameter in the request.

Path Parameter
Field Data Type Required Example
employeeName String true user001
Sample Curl Request...

curl --location --request DELETE 'http://localhost:3000/employees/user001' \
--header 'Content-Type: application/json'

Sample Response Body...

{
    "message": "Employee deleted successfully!"
}

newSalary

This API can be used to calculate the New Salary of an employee. The calculation logic is as below:

New Salary = Current Salary + (Performance Rating * Salary Multiplier). 
Salary Multiplier is:
2000 for engineer
3000 for manager
4000 for director

So, if the Current Salary of a Manager is 80000 and she has a performance rating of 4.5, then her New Salary will be:

80000 + (4.5 * 3000) = 93500

It contains the following Route:

  • /newSalary

/newSalary

Method Supported is GET

GET

Use this method to calculate the salary of an Employee. This example shows usage of Query Parameter & Header in the request.

Query Parameter
Field Data Type Required Example
employeeName String true user001
Header
Field Data Type Required Example
performanceRating Number true 4.5
Sample Curl Request...

curl --location --request GET 'http://localhost:3000/newSalary?employeeName=user001' \
--header 'Content-Type: application/json' \
--header 'performanceRating: 4.5'

Sample Response Body...

{
    "newSalary": 93500
}

restpanda's People

Contributors

simittomar avatar soniajasuja avatar

Stargazers

 avatar  avatar Anand Tripathi avatar  avatar  avatar  avatar  avatar  avatar Vivek Srivastava avatar  avatar  avatar Tauheed Khan avatar

Watchers

 avatar Anirudh Kumar Vyas avatar

Forkers

soniajasuja

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.