Set up a REST API

Want data to play with in your next egghead lesson?

John set us up with a REST API using swapi (The Star Wars API) and json-server.

As long as there is no endorsement or promotion of swapi (or Starwars), there are no issues with copyright.

If there are no special configurations needed the server can be spun up using npx

npx ships with the latest versions of npm, so you probably already have it installed.

$ npx https://github.com/johnlindquist/swapi-json-server
// --> http://localhost:3000

:boom: You now have a REST API running to interact with using Starwars data.

Build Custom data for egghead Lessons

Of course, there are endless options for building a REST API.

If your data needs to be unique for the lesson you are crafting (we have an egghead lesson for that!), John walks us through how to generate a large dataset of JSON data: Create a demo API

100 Random People

If 100 random people is good enough for you, grab this gist: gist of 100 people in json format

Serve JSON locally

json-server will serve any JSON file we have ready.

$ npm i -g json-server
$ json-server {data.json}

You're ready to go.

Host a REST API

Ziet's now is a great way to host any application needing it.

Use the app John set up:

$ npm i -g now
$ now https://github.com/johnlindquist/swapi-json-server

If this is your first time using now, there will be a small amount of set up but over-all it's a breeze.

Checkout Deploy Web Apps with Zeit Now for an in-depth look at now. :wink:

results matching ""

    No results matching ""