jQuery
If you, for example, want to create a fake user:
$.ajax({
url: "https://reqres.in/api/users",
type: "POST",
data: {
name: "paul rudd",
movies: ["I Love You Man", "Role Models"]
},
success: function(response){
console.log(response);
}
});
For which the response to this request will be...
{
"name":"paul rudd",
"movies[]":[
"I Love You Man",
"Role Models"
],
"id":"243",
"createdAt":"2014-10-18T12:09:05.255Z"
}
You can see that the API has sent us back whatever user
details we sent it, plus an
id &
createdAt key for our use.
Native JavaScript
If you've already got your own application entities, ie.
"products", you can send them in the endpoint URL, like so:
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://reqres.in/api/products/3", true);
xhr.onload = function(){
console.log(xhr.responseText);
};
xhr.send();
It would be impossible for Reqres to know your application
data, so the API will respond from a sample set of Pantone
colour data
{
"data":{
"id":3,
"name":"true red",
"year":2002,
"pantone_value":"19-1664"
}
}
It's entirely possible to get sample data into your
interface in seconds!