06: RESTful design, versions, HTTP2, HTTPS
const countries = [
{ name: 'Norway', capital: 'Oslo' },
{ name: 'Denmark', capital: 'Copenhagen' },
];
// read a resource with HTTP GET
app.get('/countries', (req, res) => {
res.send(counties);
});
// read a specific country
app.get('/countries/:name', (req, res) => {
const name = req.params.name;
return res.send(countries.find(
c => c.name === name
));
});
// delete a country
app.get('/countries/:name/delete', (req, res) => {
const name = req.params.name;
const index = countries.findIndex(
c => c.name === name
);
// remove the country
countries.splice(index, 1);
res.send(countries);
});const countries = [
{ name: 'Norway', capital: 'Oslo' },
{ name: 'Denmark', capital: 'Copenhagen' },
];
// read a resource with HTTP GET
app.get('/countries', (req, res) => {
res.send(counties);
});
// read a specific country
app.get('/countries/:name', (req, res) => {
const name = req.params.name;
return res.send(countries.find(
c => c.name === name
));
});
// delete a country
app.delete('/countries/:name', (req, res) => {
const name = req.params.name;
const index = countries.findIndex(
c => c.name === name
);
// remove the country
countries.splice(index, 1);
res.send(countries);
});// old:
app.get('/countries/:name/delete', (req, res) => {I am getting frustrated by the number of people calling any HTTP-based interface a REST API. Today’s example is the SocialSite REST API. That is RPC. It screams RPC. There is so much coupling on display that it should be given an X rating. – Roy Fielding
Hypertext does not need to be HTML on a browser. Machines can follow links when they understand the data format and relationship types. — Roy Fielding (in a comment)
Hypermedia As The Engine Of Application State
class Customer {
constructor(name) {
this.name = name;
}
}
// JSON representation
{
"name" : "Alice"
}
// HATEOAS JSON representation
{
"name": "Alice",
"links": [ {
"rel": "self",
"href": "http://localhost:8080/customer/1"
} ]
}{
"content": [ {
"price": 499.00,
"description": "Apple tablet device",
"name": "iPad",
"links": [ {
"rel": "self",
"href": "http://localhost:8080/product/1"
} ],
"attributes": {
"connector": "socket"
}
}, {
"price": 49.00,
"description": "Dock for iPhone/iPad",
"name": "Dock",
"links": [ {
"rel": "self",
"href": "http://localhost:8080/product/3"
} ],
"attributes": {
"connector": "plug"
}
} ],
"links": [ {
"rel": "product.search",
"href": "http://localhost:8080/product/search"
} ]
} http://www.slideshare.net/SimoneBordet/http2-and-java-current-status
NO TLS
WITH TLS