JumpStart – Intro on Creating your on RESTFUL API

RPC vs RESTful
(remote protocol call vs respresentational state)
(function driven vs resource driven)
eg:
example.com/createStudents
vs
example.com/students

.fetch() does not treat status code ‘errors’ (400s, 500s) as an error
axios.get() catches status code ‘errors’

CORS
Cross-origin (includes different subdomains)
to prevent malicious websites from cross origins, client can send the OPTIONS request with Origin:

Origin: http://www.example.com

Server responds with  ACAO (access control allow origin):
only allow same-origin
instead of just accept all cross-origin
CORS = middle ground

Access-Control-Allow-Origin: http://www.example.com

Flowchart showing Simple and Preflight XHR.svg

API (Application programming interface)
Interface which supplies an API method that takes an input (like a ‘black box’) and returns an output

reserved port numbers:

Making a node server
Using express:

const express = require("express");
const port = 8080;
const app = express();
app.get("/", (req, res) => {
res.end("Hello");
});
app.get("/watermelon", (req, res) => {
res.end("watermelon");
});
app.listen(8080, () => {
console.log(`Server is running on http://localhost:${port}`);
});

npm run dev (because dev is a custom command and not recognized)

middleware

Leave a comment

Design a site like this with WordPress.com
Get started