An open API service indexing awesome lists of open source software.

https://github.com/greyhatguy007/persons-api


https://github.com/greyhatguy007/persons-api

Last synced: 5 months ago
JSON representation

Awesome Lists containing this project

README

          

# Persons-API

**Note :** *The API is not yet hosted.*


Usage:


- Clone the repository

`git clone https://github.com/greyhatguy007/persons-API.git`

- Install Node dependencies

`npm install`

- Modify the port Number in server.js if needed *( Default is 3000 )*

`const port = `

- Set the verbose flag true in server.js if needed *(Default is false)*

`const verbose = true`

- Run the start script

`npm run start`


API Queries - Url


- To get all data

- Method 1 : Use wildcard `*` in search query

- Method 2 : use the following route

`http://localhost:3000/api/`

- To get a random data

`http://localhost:3000/api/random`

- Query with search and maxValue

`http://localhost:3000/api/query?query=${QUERY}&maxVal=${MAXVALUE}`

Example:

`http://localhost:3000/api/query?query=john&maxVal=50`

- Get a data of particular id

`http://localhost:3000/api/id/${ID}`

Example:

`http://localhost:3000/api/id/15325`


Usage of api - An example


To fetch a random data from terminal when deployed.
```sh
curl http://localhost:3000/api/random
```

To fetch a random data in a javascript file when deployed.
```js
const http = require('http');

const url = "http://localhost:3000/api/random";

http.get(url, (res) => {
res.on("data", (data) => {
console.log(JSON.parse(data));
});
}).on("error", (err) => {
console.log(`Error\n${err}`);
});
```

Output recieved
```
{
id: 16930,
fname: "megan",
lname: "thoma",
occupation: "teacher",
age: 24
}
```


When Deployed - UI


![ui-of-api](/public/imgs/ui.png)