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.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。