Full Stack Journey (III) 初识Axios

Axios

While I am reading other blogs and open sources, I find Axios is mentioned frequently, I have a quick glance of Axios API, looks very similar as Express, Axios also has GET, POST... Wait a minute, is Axios same as Express? Are they doing same thing? The answer is NO, they are not even comparable. They are completely two different things!!!

Axios is used at client side (AKA. frontend), for make request. Express is used at server side(AKA. backend), basically for provide server a recipe, "you now have this url, what you should do". I will talk this part more in later post, since this part confused me a lot when I first learn.

Ok go back to Axios, what is Axios? It is a Node.js package, official API gives an explanation which is super clear.

Promise based HTTP client for the brewers and node.js

Let's use GET as an instance, we want to find a user with given ID 1234

Fig 1. Three ways for GET request 

Request can be made by passing the relevant config to axios directly.

Fig 2. another way for GET request

response contains rich information, let's take a look of response schema

Fig 2. Axios response schema

So based on response schema, we can extract more detailed information about response such as data, status, statusText...

Fig 3. Get detailed info about response


In my next post (I think that would be the last one for necessary knowledge), I will take more about promise API.

你可能感兴趣的:(Full Stack Journey (III) 初识Axios)