DEV Community

Cover image for Create CRUD APIs & Deploy in almost no time
Senthilbalajiganesan
Senthilbalajiganesan

Posted on

Create CRUD APIs & Deploy in almost no time

You are a Front end developer and have no time to wait for your APIs are ready for integration? or You are backend developer and you need really quick server to set up? For a demo, Simple development practises, client reviews, etc.

In this article, we'll learn how to create a simple json based server with minimal or almost no code. Also, we ll learn how to expose the server that is running locally in your machine to outer world.

All we need ⚑️

we ll be using two different tool to do this namely json-server & ngrok. This combination really rocks. To achieve this, all we need is node.js.

Let's do it πŸš€

  • Create a file db.json
  • Create a list of schema that you would need to do a CRUD operation on. for example, you have wanted to do CRUD for simple todo items, your db.json should look like {"todo":[]} That's all ;-)
  • Now run npx json-server db.json you can optionally provide --port=1234
  • now open localhost:3000 you ll be able to see list of end points available and all the endpoint listed has GET PUT POST DELETE HTTP verb exposed.
  • To expose these APIs to out side world, run npx ngrok http 3000. and wait until you see a black screen which has public url. Any request to the URL will be forwarded to your machine and to json-server.
  • Now you can use the APIs which you could do CRUD operations on.

❌Please note these APIs will be up and running as long as your machine is running, if you close the terminal or shut down your machine, APIs will stop working as well. Although content will not be deleted as long as you didn't delete db.json❌

For more advanced setup, please refer

Hope you liked the post ;)

Top comments (1)

Collapse
 
sanjaysekaren profile image
Sanjay Chandrsekaren

Good thought to share