Server Side, REST & graphQL Flashcards
HTTP Header Query Methods:
GET
HTTP Header Mutation Methods:
POST, PUT, PATCH, DELETE
Status codes 1xx, 2xx, 3xx, 4xx, 5xx types
1xx: Informational
2xx: Success
3xx: Redirection
4xx: Client Error
5xx: Server Error
REST stands for:
REpresentational State Transfer
Status code meanings:
200, 201
200: Everything went well
201: A resource was created properly
(probably from a PUSH request)
Status code meanings:
307
This resource has moved temporarily
Status code meanings:
404, 500
404: You requested a nonexistent resource
500: Something went wrong server side (general error)
RESTful heuristics tips: (verbs/plurals)?
Don’t use verbs in the restful url, use the correct HTTP method instead
Use plurals for collections, followed by an :id for the specific item
All lowercase
Don’t use spaces or underscores. Use hyphens
No file extensions
REST disadvantages
Can be a lot of endpoints
Can ‘over-fetch’ whole objects when you only need a small part
Need to know what the end user will request, so you can design the end points
REST advantages
Very familiar standard structure
import and initialize express server
const express = require(“express”);
const setupServer = () => { const app = express(); app.get("/api/pokemon", (req, res) => {
res.send(pokeData); });
return app;
};
graphQL benefits
prevents overfetching and underfetching
is kind of ‘self documenting’
types of graphQl operations
queries (asks for data. Let GET)
mutations (alters data, like POST, PUT, PATCH, DELETE)
Two parts of graphQL server:
schema
resolver
graphQl schema and resolver example (for orders)
Schema:
type Query {
order (id: Int): Order
}
Resolver:
order (params) => {
return order
}