https://github.com/yeehanchung/local-mock-api
For faster local testing and prototyping
https://github.com/yeehanchung/local-mock-api
api rest-api restful-api
Last synced: 2 months ago
JSON representation
For faster local testing and prototyping
- Host: GitHub
- URL: https://github.com/yeehanchung/local-mock-api
- Owner: yeehanchung
- License: mit
- Created: 2020-08-30T05:38:14.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-01-30T04:42:53.000Z (over 4 years ago)
- Last Synced: 2025-01-16T04:40:52.642Z (4 months ago)
- Topics: api, rest-api, restful-api
- Homepage:
- Size: 67 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple API for testing
- Able to `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS`.
- Changes are persisted between calls.## Getting started
1. Clone this repository on terminal `git clone `.
2. Open cloned directory `simple-api-for-testing`.
3. If you haven't installed `json-server`, type `npm i json-server` on terminal to install.
4. After installation, start JSON Server locally by typing `json-server --watch db.json` on terminal.
5. Server is started locally on `http://localhost:3000`.## 🚨 Issue
### 1. `Missing write access to .../node_modules`?
Run this command: `sudo chown -R $USER /usr/local/lib/node_modules`
- `sudo` means running the command as the system super user, root user.
- `chown` changes the owner of the file or folder.
- `-R` changes the owner, so that we can get root access to all files inside the node_modules folder.
- `$USER` is an environment variable, and by default it is your system username.
- Finally, you can `npm install -g json-server`.## `db.json`
```json
{
"player": [
{
"id": 1,
"name": "John Doe",
"hobbies": [
"Cycling",
"Netlix",
"Travelling"
],
"addresses": [
{
"addressId": "1",
"postalCode": "7400",
"country": "Malaysia",
"state": "Kuala Lumpur",
"line1": "Jane Street, 191"
}
]
},
{
"id": 2,
"name": "Marry Lane",
"hobbies": [
"Rock climbing",
"Eating"
],
"addresses": [
{
"addressId": "1",
"postalCode": "2100",
"country": "Malaysia",
"state": "Selangor",
"line1": "Elementi, 200"
}
]
}
]
}
```## References
1. [JSON Server](https://www.npmjs.com/package/json-server) from npmjs.
2. [How to fix the "Missing write access" error when using npm](https://flaviocopes.com/npm-fix-missing-write-access-error/).
3. [RESTful API Design - PUT vs PATCH](https://medium.com/backticks-tildes/restful-api-design-put-vs-patch-4a061aa3ed0b).