2

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 Simple app there is no database connection. Now I want to add Db for storing tasks. but as a newbie, I don't know how to make Http request for edit delete and add a task. please explain with a example. Any help will be appreciated. Thank you.

1

3 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

Comments

0

There are many npm modules for http request. Here is a smiple one: https://github.com/request/request

Comments

0
install axios

$ npm install axios


import axios

import axios from 'axios';

get request

axios.get('api url').then(function (response) {
    console.log(response);
}).catch(function (error) {
    console.log(error);
});


post request

var body = {
    firstName: 'testName',
    lastName: 'testLastName'
};

axios.post('api url',body).then(function (response) {
    console.log(response);
}).catch(function (error) {
    console.log(error);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.