Michał Michalczuk
I am fullstack software developer #dotnet #angular #typescript, IT trainer. Both fascinated and terrified by technology advancement.
for front-end devs
Michał Michalczuk
Ciklum / Stibo Systems
infoShare Academy
let NOTES = [];
const get = () => Promise.resolve(NOTES);
const create = (note) => {
NOTES.push(note);
return Promise.resolve(note);
};
const deleteItem = (note) =>
NOTES = NOTES.filter(item => item.id !== note.id);
const update = (id, note) => {
let toUpdate = NOTES.find(item => item.id === id);
toUpdate = note;
}
+ Fast to achieve
+ Works
+ You have it under control
- There could be some subtle differences between working with data in memory and with data fetched from API
- After read back-end arrives - you have to change your code
- It spreads across your app
We have plenty of options
First, lets take a look at benefits
const baseApiUrl = 'http://fake-api.example.com';
// after switching to real back-end
// const baseApiUrl = 'http://real-api.example.com';
+ Fast to achieve
+ Works
+ You have it under control
+ Only configuration change (the API base URL) in front-end app
+ Still playing with HTTP calls - no surprises here
- Another point of failure
How APIs are documented?
### Get a single Note [GET /notes/{id}]
Get single note from collection by `id`
+ Parameters
+ id (required, Number, `2`) ... Numeric `id` of the note
+ Response 200 (application/json)
{
"id": 2,
"title": "Second note",
"content": "Second note sample content",
"createdOn": "2018-01-02T16:30:00.511Z",
"type": 2
}
Write your contracts in Markdown syntax.
Nice!
Demo
*It would be nice if data would be persisted
*You can tweak it, and deploy it as a server
Demo
Demo
But be carefull with adding too much logic there.
You want to fake API or write another one?
By Michał Michalczuk
Ciklum UX & Front-end meetup, 27.06.2018 Gdańsk
I am fullstack software developer #dotnet #angular #typescript, IT trainer. Both fascinated and terrified by technology advancement.