Skip to content
Ben Casalino edited this page May 23, 2018 · 1 revision

Postman Use nodemon to run:

API API: Application Programming Interface - A set of definitions protocols and tools for building and application using its data. Receives and sends responses. An API isn’t the same as the remote server — rather it is the part of the server that receives requests and sends responses. Web Service: if the input/output requests happen over the internet , it’s a web service.

Program: Inputs/Outputs something that takes inputs → does something → outputs something. The API is the “contact points” if i give you this input → you give me this output.

Requests: HTTP request to pokemon API (INPUT)(PARAMETERS/ARGUMENTS → return “Bulbasaur” (OUTPUT)(RETURN STATEMENT) ← makes up the “API” of the function

RESTful APIs: are those that conform with REST architectural style. REST is considered an underlying architectural principle of the web, and it’s safe to say RESTful APIs are the most common Web APIs. There are many rules to follow with REST, but here are several that first come to mind: REST uses 4 HTTP verbs to describe the type of each request: GET (request record) PUT (update record) POST (create record) DELETE (delete record)

An architectural style called REST (Representational State Transfer) advocates that web applications should use HTTP as it was originally envisioned. Lookups should use GET requests. PUT, POST, and DELETE requests should be used for mutation, creation, and deletion respectively.

REST is stateless, meaning all the information required to process a given request is contained within the request itself. The server doesn’t need to know of previous requests in order to process the current request. For example, if you are logged in on some website, the server will expect your client to send the authentication credentials with each request — that is the only way the server knows that you are still you across a series of requests. APIs don’t have to be RESTful. I totally agree. In fact, even on the Web, the data transfer doesn’t have to conform to all of the REST principles. REST is just a prevalent style that works well with HTTP protocol. APIs are much more than just Web APIs. Some examples of non-RESTful non-Web APIs from my post are with Object Oriented Design and APIs of software libraries, such as JQuery.

REST and GraphQL: Are two popular ways to send data across HTTP.

GraphQL: With GraphQL, you can always fetch all the initial data required by a view with a single round-trip to the server. To do the same with a REST API, we need to introduce unstructured parameters and conditions that are hard to manage and scale. Clients dependency on servers: With GraphQL, the client speaks a request language which: 1) eliminates the need for the server to hardcode the shape or size of the data, and 2) decouples clients from servers. This means we can maintain and improve clients separately from servers. The bad front-end developer experience: With GraphQL, developers express the data requirements of their user interfaces using a declarative language. They express what they need, not how to make it available. There is a tight relationship between what data is needed by the UI and the way a developer can express a description of that data in GraphQL

GraphQL is all about data communication. You have a client and a server and both of them need to talk with each other. The client needs to tell the server what data it needs, and the server needs to fulfill this client’s data requirement with actual data. GraphQL steps into the middle of this communication.

Get/Post Fetch is a tool for making a HTTP request. Fetch generates the get for example. Get,Put/Patch,Create,Read,Update,Delete,Post etc are types of HTTP Requests: app.get('/', function(request, response) { response.json(result); // response.json(data.cites); }); app.post("/", (request, response) => { result.push(request.body) response.json(result); });

Fetch API Fetch API: Uses the GET method by default.

fetch(url) // Call the fetch function passing the url of the API as a parameter .then(function() { // Your code for handling the data you get from the API }) .catch(function() { // This is where you run code if the server returns any errors });

Fetch API methods: clone() - As the method implies this method creates a clone of the response. redirect() - This method creates a new response but with a different URL. formData() - Also returns a promise but one that resolves with FormData object. blob() - This is one resolves with a Blob. text() - In this case it resolves with a string. json() - Lastly we have the method to that resolves the promise with JSON.

Clone this wiki locally