how to Make Http request from reactjs ?

前端 未结 3 561
生来不讨喜
生来不讨喜 2021-01-15 18:41

I am using react js as front end and zf3 as a backend in my ToDo application. I put all my React folder and files in public folder of Zend project. As of now, it is just S

3条回答
  •  难免孤独
    2021-01-15 19:31

    I use axios. It allows you to set some default configuration so that you don't need to do it with every request:

    axios.defaults.headers.common.Authorization = "my-awesome-token";
    axios.defaults.baseURL = http://www.somehost.com/api;
    ...
    axios.get('/people')
        .then(response => handleResponse(response))
        .catch(error => handleError(error)) 
    // actually shoots to http://www.somehost.com/api/people with Authorization header
    

提交回复
热议问题