FunRequestThe have the get, post, patch and delete methods
Method | Description | parameters |
---|---|---|
get() | To create a get request | `url :any, headers:object` |
post() | To create a post request | `url:String, body:any, headers:object` |
patch() | To create a patch request | `url:String, body:any, headers:object` |
delete() | To create a delete request | `url:String, headers:object` |
#
Simple get request
Lets send a simple get request to the url `https://jsonplaceholder.typicode.com/users`, it will return a users profile and we will display the profile.
React / Next.js Show Source Code
Returned Data
{"id":3,"name":"Clementine Bauch","username":"Samantha","email":"Nathan@yesenia.net","address":{"street":"Douglas Extension","suite":"Suite 847","city":"McKenziehaven","zipcode":"59590-4157","geo":{"lat":"-68.6102","lng":"-47.0653"}},"phone":"1-463-123-4447","website":"ramiro.info","company":{"name":"Romaguera-Jacobson","catchPhrase":"Face to face bifurcated interface","bs":"e-enable strategic applications"}}
#
Post Request
In this example, we will send a post request to `https://jsonplaceholder.typicode.com/posts`, {
title: 'foo',
body: 'bar',
userId: 1,
}
Data
React / Next.js Show Source Code
#
Patch Request
In this example, we will send a patch request to `https://jsonplaceholder.typicode.com/posts/1`, {
title: 'Patch Request',
body: 'This is the content of the data',
userId: 1,
}
Data
React / Next.js Show Source Code
#
Delete Request
In this example, we will send a delete request to `https://jsonplaceholder.typicode.com/posts/1`,
React / Next.js Show Source Code