-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #234 from SatwikMohan/medicine_api
[New API] : A-Z Medicine API for India
- Loading branch information
Showing
13 changed files
with
2,888 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Medicine API for India | ||
|
||
## Installation | ||
|
||
To use this program, you need to have Node.js installed. Then, install the required `express` library by running: | ||
|
||
```sh | ||
npm i express | ||
``` | ||
|
||
## Method to use the API | ||
|
||
1. Run the index.mjs file using the following command: | ||
```sh | ||
node index.mjs | ||
``` | ||
|
||
OR | ||
|
||
```sh | ||
nodemon index.mjs | ||
``` | ||
|
||
2. Use the enpoints to get your desired service. | ||
|
||
3. Endpoint 1 - /searchByName | ||
To get the data of the medicine with the following name | ||
|
||
GET - http://localhost:80/searchByName?name=(Enter Medicine Name) | ||
|
||
Query Parameter => name | ||
|
||
eg - name = Zaling Plus Tablet CR | ||
|
||
```bash | ||
|
||
{ | ||
"result": [ | ||
{ | ||
"id": 249154, | ||
"name": "Zaling Plus Tablet CR", | ||
"price": 165, | ||
"Is_discontinued": "FALSE", | ||
"manufacturer_name": "Mitis Biomedics Ltd", | ||
"type": "allopathy", | ||
"pack_size_label": "strip of 10 tablet cr", | ||
"short_composition1": "Paroxetine (12.5mg) ", | ||
"short_composition2": " Clonazepam (0.5mg)" | ||
} | ||
] | ||
} | ||
|
||
``` | ||
|
||
4. Endpoint 2 - /searchByManufacturer | ||
To get the data of the medicine with the following manufacturer's name | ||
|
||
GET - http://localhost:80/searchByManufacturer?manufacturer=(Enter Manufacturer Name) | ||
|
||
Query Parameter => manufacturer | ||
|
||
eg - manufacturer = Mitis Biomedics Ltd | ||
|
||
```bash | ||
|
||
{ | ||
"result": [ | ||
{ | ||
"id": 249154, | ||
"name": "Zaling Plus Tablet CR", | ||
"price": 165, | ||
"Is_discontinued": "FALSE", | ||
"manufacturer_name": "Mitis Biomedics Ltd", | ||
"type": "allopathy", | ||
"pack_size_label": "strip of 10 tablet cr", | ||
"short_composition1": "Paroxetine (12.5mg) ", | ||
"short_composition2": " Clonazepam (0.5mg)" | ||
} | ||
] | ||
} | ||
|
||
``` | ||
|
||
5. Endpoint 3 - /AllDiscontinued | ||
To get the data of the medicines which are discontinued | ||
|
||
GET - http://localhost:80/AllDiscontinued | ||
|
||
6. Endpoint 4 - /searchByPrice | ||
To get the data of all the medicines with the following price | ||
|
||
GET - http://localhost:80/searchByPrice?price=(Enter the price) | ||
|
||
Query Parameter => price | ||
|
||
eg - price = 90 | ||
|
||
7. Endpoint 5 - /searchByPriceUnder | ||
To get the data of all the medicines under the following price | ||
|
||
GET - http://localhost:80/searchByPriceUnder?price=(Enter the price) | ||
|
||
Query Parameter => price | ||
|
||
eg - price = 90 | ||
|
||
8. Endpoint 6 - /searchByPriceAbove | ||
To get the data of all the medicines above the following price | ||
|
||
GET - http://localhost:80/searchByPriceAbove?price=(Enter the price) | ||
|
||
Query Parameter => price | ||
|
||
eg - price = 90 | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import express from 'express' | ||
import router from './routes.mjs'; | ||
const app = express(); | ||
app.use(express.json()); | ||
app.use(router); | ||
const PORT = process.env.PORT||80; | ||
app.listen(PORT,()=>{ | ||
console.log("Running on port "+PORT); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module.exports={ | ||
searchByNameMiddleware:function(request,response,next){ | ||
const {query} = request; | ||
if(!query){ | ||
return response.status(400).send({msg:"name field query is required"}); | ||
}else{ | ||
const name = query.name; | ||
console.log(name); | ||
if(!(typeof name == "string")|| name.length==0){ | ||
return response.status(400).send({msg:"Invalid field value"}); | ||
} | ||
query.name = name.toLocaleLowerCase().trim().replaceAll(" ",""); | ||
} | ||
next(); | ||
}, | ||
searchByManufacturerMiddleware:function(request,response,next){ | ||
const {query} = request; | ||
if(!query){ | ||
return response.status(400).send({msg:"manufacturer field query is required"}); | ||
}else{ | ||
const manufacturer = query.manufacturer; | ||
console.log(manufacturer); | ||
if(!(typeof manufacturer == "string")|| manufacturer.length==0){ | ||
return response.status(400).send({msg:"Invalid field value"}); | ||
} | ||
query.manufacturer = manufacturer.toLocaleLowerCase().trim().replaceAll(" ",""); | ||
} | ||
next(); | ||
}, | ||
searchByPriceMiddleware:function(request,response,next){ | ||
const {query} = request; | ||
if(!query){ | ||
return response.status(400).send({msg:"price field query is required"}); | ||
}else{ | ||
const price = query.price; | ||
console.log(price); | ||
if(!(typeof price == "string")|| price.length==0){ | ||
return response.status(400).send({msg:"Invalid field value"}); | ||
} | ||
} | ||
next(); | ||
} | ||
} |
Oops, something went wrong.