How to build your Backend?
Create a table
CREATE TABLE IF NOT EXISTS friend (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT
);
Add some data
INSERT INTO friend (name) VALUES ('Jennifer');
INSERT INTO friend (name) VALUES ('Courteney');
INSERT INTO friend (name) VALUES ('Lisa');
Let's check how it goes
SELECT * FROM friend
Define an API
api:
service: web-app
query: SELECT * FROM friend LIMIT COALESCE(@limit, 10)
method: GET
path: /friend
headers: {
Access-Control-Allow-Origin: '*',
Access-Control-Allow-Methods: 'GET',
Cache-Control: 'max-age=3600',
}
Get the token
token:
service: web-app
Enjoy it ;)
fetch('https://odb.dev/api/friend?limit=2', {
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
}
});
Try it
https://stackblitz.com/edit/js-r8jne8