alyaazizzaman / Hello-API

A tutorial to let the students launch an api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hello API

Today we will write our first API and make a call to it.

Step One

In the server.js file create an HTTP server, there is already a function to read a file.

  1. When it receives a request with url / or /index.html send the file index.html as the response.
  2. When it receives a request with /app.js send the file app.js as the response
  3. When it receives a request with /api send the file data.json as a the response.
  4. When it receives a request with any other URL send message back to the user with statusCode 404.

BONUS

In the app.js

  1. Make an AJAX get request using jQuery to the url localhost:8000/data.json
  2. console.log the result

Testing

  1. Open localhost:8000 in the browser with the url you want to test.
  2. For the bonus: open up the console and see the result!

About

A tutorial to let the students launch an api


Languages

Language:JavaScript 84.6%Language:HTML 15.4%