Consume API with react

0

Can anyone help me with how can I consult this API?

## Cadastro
'''sh
$ curl --request POST \
 --url https://dev.people.com.ai/mobile/api/v2/register \
 --header 'content-type: application/json' \
 --data '{
"email":"[email protected]",
"name":"Lennon Coelho",
"password":"Senha@12346"
}'

## Login
'''sh
$ curl --request POST \
 --url https://dev.people.com.ai/mobile/api/v2/login \
 --header 'content-type: application/json' \
 --data '{
"email":"[email protected]",
"password":"Senha@12346"
}'
    
asked by anonymous 19.09.2018 / 15:48

1 answer

2

You must use the fetch method by entering the API address, identify the method ( POST , PUT , GET , DELETE ), insert the required header and send the data in the request body.

Registration

fetch('https://dev.people.com.ai/mobile/api/v2/register/', {
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    email: '[email protected]',
    name: 'Lennon Coelho',
    password: 'Senha@12346',
  })
}).then((response) => {
    return response;
});

Login

fetch('https://dev.people.com.ai/mobile/api/v2/login/', {
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    email: '[email protected]',
    password: 'Senha@12346',
  })
}).then((response) => {
    return response;
});

If this is your first time using fetch, in some cases you will need to install and import it, follow the link . .

Additionally you can install some extension like Axios or jQuery AJAX which make calling REST methods easier.

    
19.09.2018 / 16:43