?print-pdf
' Created by
HTTP method | Description |
---|---|
GET | used to read (or retrieve) a representation of a resource. |
POST | most-often utilized to create new resources. |
PUT | most-often utilized to update resources |
DELETE | most-often utilized to delete resources. |
eval()
)
{
'fruits': ['apple', 'orange', 'banana'],
}
apple
orange
banane
name:value
pairs, delimited by curly braces, where the names (also called keys) are strings. Pairs are separated by comma (trailing comma is not allowed)
{
"todos": [
{
"title": "Learn HTML",
"completed": true,
"id": 1
},
{
"title": "Learn CSS",
"completed": true,
"id": 2
},
{
"title": "Learn JS",
"completed": true,
"id": 3
}
]
}
const data = JSON.parse(jsonString);
// this is NOT a JS object, it's JUST a string
const jsonData = ` {
"title": "Learn HTML",
"completed": true,
"id": 1
}`;
console.log(typeof jsonData);
// parse json in rder to get the js object:
const data = JSON.parse(jsonData)
console.log(typeof data);
var json = JSON.stringify(obj);
// this is a JS object
const data = {
"title": "Learn HTML",
"completed": true,
"id": 1
};
console.log(typeof data);
// let's convert it into JSON string:
const dataJSON = JSON.stringify(data)
console.log(typeof dataJSON);
response.json()
method returns a promise which resolves with the result of parsing the body text as JSON.
const url = 'https://jsonplaceholder.typicode.com/todos/1';
fetch(url)
.then( response => response.json() )
.then( todoObj => console.log(todoObj.title) )
http://api.icndb.com/jokes/random
URL to fetch the joke data.
These slides are based on
customised version of
framework