api - how to make a restAPI call to laravel using react -


currently, restapi , app both hosted on xampp. restapi url laravel.dev.

my post route looks so...

route::post('/content', 'test@save'); 

and controller...

class test extends controller {     public function save()      {         return "here";     } } 

pretty simple, want make post request route app. trying using react's fetch, not know url put since attempt not work...

fetch('laravel.dev', {         method: 'post',         headers: {             'accept': 'application/json',             'content-type': 'application/json',         },         body: json.stringify({             firstparam: 'yourvalue',             secondparam: 'yourothervalue',         })     })     .then((response) => response.json())     .then((responsejson) => {         console.log(responsejson);     }); 

i don't care passing route, want successful call restapi server. right i'm getting...

post http://localhost/app/src/laravel.dev 404 (not found) 

that wrong path well, /app app , trying call restapi server.

what need change make successful call?

fetch needs protocol. right tries request "local" resource. also, add endpoint:

fetch('http://laravel.dev/content', {   // ... }); 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -