API Validation

alt text

Problem statement

The problem statement is to create a couple of endpoints. The structure of request response has been shared with the user.


API contract

GET /caluclator/greeting

Checks whether the service is available.

Response
  • Code: 200
  • Content: Hello world!
POST /calculator/add

Adds two given numbers

Request & Response headers

Content-Type: application/json

Body
{
    first: number,
    second: number
}
Success Response
  • Status code: 200
  • Content: { result: result-of-the-summation }
POST /calculator/subtract

Subtracts two given numbers

Request & Response headers

Content-Type: application/json

Body
{
    first: number,
    second: number
}
Success Response
  • Status code: 200
  • Content: { result: result-of-the-subtraction }
How to submit a solution

In order to submit a solution, follow these steps.

  • Fork the API-Validation repository (How to fork a repository github)
    • Deselect the "Copy the main branch only" to copy other language demos as well
  • Clone the forked repository (How to clone a repository github)
  • Change the branch according to the language of your choice (This demo is available in (language-> branch) "node" -> "Node", "python" -> "Python" ) (How to change branches git )
  • Enable workflows in your github fork (Under the actions tab -> Select "I understand my workflows, go ahead and enable them" to enable the test workflow)
  • Use your favourite editor to make changes
  • Create a commit after testing it locally (How to commit git)
  • Push the commit to the remote to the same branch (github repo) (How to push git)
  • If all your changes work well, you will see a green tick on the actions section on your repo under the selected branch (How to see last run action)
    • If it's a cross mark, the logs will tell you what you did wrong.
    • Fix the issue, and repeat steps 4+ to resubmit
  • Congratulations, you have successfully solved the problem

Note

Set Secrets Environment variable:

Repo -> Settings -> Security -> Secrets and variables -> Actions -> New repository secret ->

Name = "COLLECTIONID"
Secret = "<collectionID>"

Name = "POSTMANAPIKEY"
Secret = "<apikey>"

Name = "MAIL_USERNAME"
Secret = "<username>"

Name = "MAIL_PASSWORD"
Secret = "<password>"

Name = "SENDER_MAIL"
Secret = "<emailID>"