fetch('https://PROJECT_TOKEN.restler.io/tasks', {
method: 'GET',
headers: {'content-type': 'application/json'},
}).then(res => {
if (res.ok) {
return res.json();
}
// handle error
}).then(tasks => {
// Do something with the list of tasks
}).catch(error => {
// handle error
})
const newTask = {
content: 'Check out restler.io',
completed: false,
};
fetch('https://PROJECT_TOKEN.restler.io/tasks', {
method: 'POST',
headers: {'content-type':'application/json'},
// Send your data in the request body as JSON
body: JSON.stringify(newTask)
}).then(res => {
if (res.ok) {
return res.json();
}
// handle error
}).then(task => {
// do something with the new task
}).catch(error => {
// handle error
})
fetch('https://PROJECT_TOKEN.restler.io/tasks/1', {
method: 'PUT', // or PATCH
headers: {'content-type':'application/json'},
body: JSON.stringify({completed: true})
}).then(res => {
if (res.ok) {
return res.json();
}
// handle error
}).then(task => {
// Do something with updated task
}).catch(error => {
// handle error
})
fetch('https://<PROJECT_TOKEN.restler.io/tasks/1', {
method: 'DELETE',
}).then(res => {
if (res.ok) {
return res.json();
}
// handle error
}).then(task => {
// Do something with deleted task
}).catch(error => {
// handle error
})
const url = new URL('https://PROJECT_TOKEN.restler.io/tasks');
url.searchParams.append('completed', false); //https://PROJECT_TOKEN.restler.io/tasks?completed=false
fetch(url, {
method: 'GET',
headers: {'content-type':'application/json'},
}).then(res => {
if (res.ok) {
return res.json();
}
// handle error
}).then(tasks => {
// restler returns only incomplete tasks
}).catch(error => {
// handle error
})
const url = new URL('https://PROJECT_TOKEN.restler.io/tasks');
url.searchParams.append('completed', false); //https://PROJECT_TOKEN.restler.io/tasks?completed=false
url.searchParams.append('page', 1); //https://PROJECT_TOKEN.restler.io/tasks?completed=false&page=1
url.searchParams.append('limit', 10); //https://PROJECT_TOKEN.restler.io/tasks?completed=false&page=1&limit=10
fetch(url, {
method: 'GET',
headers: {'content-type':'application/json'},
}).then(res => {
if (res.ok) {
return res.json();
}
// handle error
}).then(tasks => {
// restler returns first 10 tasks that are not completed
}).catch(error => {
// handle error
})
fetch('https://PROJECT_TOKEN.restler.io/users/1/tasks', {
method: 'GET',
headers: {'content-type':'application/json'},
}).then(res => {
if (res.ok) {
return res.json();
}
// handle error
}).then(tasks => {
// Do something with the list of tasks
}).catch(error => {
// handle error
})
const newTask = {
content: 'Check out restler.io',
completed: false,
};
fetch('https://PROJECT_TOKEN.restler.io/users/1/tasks', {
method: 'POST',
headers: {'content-type':'application/json'},
// Send your data in the request body as JSON
body: JSON.stringify(newTask)
}).then(res => {
if (res.ok) {
return res.json();
}
// handle error
}).then(task => {
// do something with the new task
}).catch(error => {
// handle error
})
fetch('https://PROJECT_TOKEN.restler.io/user/1/tasks/1', {
method: 'PUT', // or PATCH
headers: {'content-type':'application/json'},
body: JSON.stringify({completed: true})
}).then(res => {
if (res.ok) {
return res.json();
}
// handle error
}).then(task => {
// Do something with updated task
}).catch(error => {
// handle error
})
fetch('https://<PROJECT_TOKEN.restler.io/users/1/tasks/1', {
method: 'DELETE',
}).then(res => {
if (res.ok) {
return res.json();
}
// handle error
}).then(task => {
// Do something with deleted task
}).catch(error => {
// handle error
})
const url = new URL('https://PROJECT_TOKEN.restler.io/users/1/tasks');
url.searchParams.append('title', 'hello');
fetch(url, {
method: 'GET',
headers: {'content-type':'application/json'},
}).then(res => {
if (res.ok) {
return res.json();
}
// handle error
}).then(tasks => {
// restler returns only tasks that match `hello` string
}).catch(error => {
// handle error
})
const url = new URL('https://PROJECT_TOKEN.restler.io/users/1/tasks');
url.searchParams.append('completed', false);
fetch(url, {
method: 'GET',
headers: {'content-type':'application/json'},
}).then(res => {
if (res.ok) {
return res.json();
}
// handle error
}).then(tasks => {
// restler returns only incomplete tasks
}).catch(error => {
// handle error
})
const url = new URL('https://PROJECT_TOKEN.restler.io/users/1/tasks');
url.searchParams.append('completed', false);
url.searchParams.append('page', 1);
url.searchParams.append('limit', 10);
fetch(url, {
method: 'GET',
headers: {'content-type':'application/json'},
}).then(res => {
if (res.ok) {
return res.json();
}
// handle error
}).then(tasks => {
// restler returns first 10 tasks that are not completed
}).catch(error => {
// handle error
})
const url = new URL('https://PROJECT_TOKEN.restler.io/users/1/tasks');
url.searchParams.append('sortBy', 'title');
url.searchParams.append('order', 'desc'); // order parameter is optional and will default to `asc`
fetch(url, {
method: 'GET',
headers: {'content-type':'application/json'},
}).then(res => {
if (res.ok) {
return res.json();
}
// handle error
}).then(tasks => {
// list of tasks sorted by title in descending order
}).catch(error => {
// handle error
})
{
"count": 60,
"tasks": [
{
"completed": false,
"title": "Checkout restler.io!",
"id": "1"
}
]
}
{
"anyKey": "anyValue",
"count": "$count",
"tasks": "$mockData",
"requestId": "$datatype.uuid"
}