https://github.com/max9159/dynamic-api-exercises
A dynamic API service support custom your response fields, filter, sorting.
https://github.com/max9159/dynamic-api-exercises
Last synced: 3 months ago
JSON representation
A dynamic API service support custom your response fields, filter, sorting.
- Host: GitHub
- URL: https://github.com/max9159/dynamic-api-exercises
- Owner: max9159
- License: mit
- Created: 2022-08-18T14:25:30.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-21T04:25:17.000Z (almost 3 years ago)
- Last Synced: 2025-01-26T17:22:43.193Z (4 months ago)
- Language: JavaScript
- Size: 2.07 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Roadmap: ROADMAP.md
Awesome Lists containing this project
README
# dynamic-api-exercises
## Abstract
> A dynamic API service supports custom response fields, filter, and sorting and is written in GraphQL and NodeJS.
> Due to the short schedule, I choose to implement it on the application directly without DataBase(another dependency) to quickly finish the PoC.## Installation
- Ensure you have install NodeJS.
- https://nodejs.org/en/download/
```bash
npm install
```## Getting Started
- To start API service.
```bash
npm start
```## API Testing Example
- You can refer to this http file [integrationTests.http](./src/tests/integrationTests.http) to do API Testing.
- Below API including custom fields, filter, sort
- **API Path:** http://localhost:9090/api/salaries
- **API Query:**
```js
?query=query($filter:Filter!,$sort:Sort){
salaries(filter:$filter,sort:$sort)
{timestamp,jobTitle,annualBasePay}
}
&variables={
"filter":{"jobTitle":"Engineer","timestamp_lte":"1458566204000"},
"sort":{"timestamp":"DESC"}
}
```
- Custom fields
- salaries(filter:$filter,sort:$sort)**{timestamp,jobTitle,annualBasePay}**
- Filter
- &variables={**"filter":{"jobTitle":"Engineer","timestamp_lte":"1458566204000"}**}
- timestamp_lte
- Need to use the new Date().getTime() in javascript.
- Sort
- &variables={"filter":{"jobTitle":"Engineer","timestamp_lte":"1458566204000"},**"sort":{"timestamp":"DESC"**}}## Preview
- Run server and send GET Request via HTTP Client Extension.

- Use GET API with Chrome.
