Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/imran120198/my-api-mocker
Deploy API using cyclic
https://github.com/imran120198/my-api-mocker
Last synced: 2 days ago
JSON representation
Deploy API using cyclic
- Host: GitHub
- URL: https://github.com/imran120198/my-api-mocker
- Owner: imran120198
- Created: 2022-11-28T11:32:52.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-29T07:24:59.000Z (almost 2 years ago)
- Last Synced: 2023-03-10T04:49:33.643Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://nice-red-goldfish-coat.cyclic.app
- Size: 128 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# How to build API using cyclic
## Create a package in VS Code
````
npm init -y````
## Install pacakages
````
npm install json-server json-serve corsnpm install -D nodemon
````
## Create index.js file write down the below code
````
const jsonServer = require('json-server')
const cors = require('cors')
const path = require('path')const server = jsonServer.create()
const router = jsonServer.router(path.join(__dirname, 'db.json'))
const middlewares = jsonServer.defaults()server.use(cors())
server.use(jsonServer.bodyParser)
server.use(middlewares)
server.use(router)const PORT = 8000
server.listen(PORT, () => {
console.log(`JSON Server is running on http://localhost:${PORT}`)
})
````## Create a db.json file and build your data
````
[
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
},
{
"userId": 1,
"id": 2,
"title": "qui est esse",
"body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"
},
{
"userId": 1,
"id": 3,
"title": "ea molestias quasi exercitationem repellat qui ipsa sit aut",
"body": "et iusto sed quo iure\nvoluptatem occaecati omnis eligendi aut ad\nvoluptatem doloribus vel accusantium quis pariatur\nmolestiae porro eius odio et labore et velit aut"
}
]
````## Edit your a code in script tag in your pacakage
````
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
},
````## Create your account in cyclic with your github
````
https://www.cyclic.sh/
````## select your repository link and deploy