https://github.com/greyhatguy007/persons-api
https://github.com/greyhatguy007/persons-api
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/greyhatguy007/persons-api
- Owner: greyhatguy007
- Created: 2023-03-05T18:13:55.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-06T17:03:27.000Z (over 3 years ago)
- Last Synced: 2025-05-12T11:57:31.781Z (about 1 year ago)
- Language: HTML
- Size: 541 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
