SlideShare ist ein Scribd-Unternehmen logo
1 von 64
Downloaden Sie, um offline zu lesen
API дизайн: уроки
известных проектов
Aндрей Саломатин
2018-10-26 @flpvsk @KyivJS
Мы возможно встречались на
—MoscowJS
—Frontend Unioin Conf
—RadioJS
2018-10-26 @flpvsk @KyivJS 2
Code Podcast
codepodcast.com
—Об общих концепциях в программировании
—Тематические эпизоды
—На английском
2018-10-26 @flpvsk @KyivJS 3
В этом докладе
—3 примера дизайна
—API систем
—Много абстрактной информации
2018-10-26 @flpvsk @KyivJS 4
В этом докладе
—3 примера дизайна
—API систем
—Много абстрактной бесполезной
информации
2018-10-26 @flpvsk @KyivJS 5
Зачем?
2018-10-26 @flpvsk @KyivJS 6
Application
Programming
Interface2018-10-26 @flpvsk @KyivJS 7
#1
Цена
абстракции2018-10-26 @flpvsk @KyivJS 8
DOM
API2018-10-26 @flpvsk @KyivJS 9
Примеры
2018-10-26 @flpvsk @KyivJS 10
2018-10-26 @flpvsk @KyivJS 11
2018-10-26 @flpvsk @KyivJS 12
2018-10-26 @flpvsk @KyivJS 13
Immediate Mode GUI
2018-10-26 @flpvsk @KyivJS 14
#2
Адрес /
Содержимое2018-10-26 @flpvsk @KyivJS 15
Адрес = содержимое
GET '/person/flpvsk'
PUT '/person/flpvsk'
POST '/person/flpvsk/posts'
2018-10-26 @flpvsk @KyivJS 16
Пример
!
--> POST { text: 'I love all' } '/flpvsk/posts'
"
<-- { id: 'addr1' }
#
--> POST { share: 'newId' } '/kickz/posts'
"
<-- { id: …, share: 'newId' }
!
--> PUT { text: 'I hate birds' } '/flpvsk/posts/addr1'
2018-10-26 @flpvsk @KyivJS 17
Пример
!
--> POST { text: 'I love all' } '/flpvsk/posts'
"
<-- { id: 'addr1' }
#
--> POST { share: 'newId' } '/kickz/posts'
"
<-- { id: …, share: 'newId' }
!
--> PUT { text: 'I hate birds' } '/flpvsk/posts/addr1'
2018-10-26 @flpvsk @KyivJS 17
Пример
!
--> POST { text: 'I love all' } '/flpvsk/posts'
"
<-- { id: 'addr1' }
#
--> POST { share: 'newId' } '/kickz/posts'
"
<-- { id: …, share: 'newId' }
!
--> PUT { text: 'I hate birds' } '/flpvsk/posts/addr1'
2018-10-26 @flpvsk @KyivJS 17
Пример
!
--> POST { text: 'I love all' } '/flpvsk/posts'
"
<-- { id: 'addr1' }
#
--> POST { share: 'newId' } '/kickz/posts'
"
<-- { id: …, share: 'newId' }
!
--> PUT { text: 'I hate birds' } '/flpvsk/posts/addr1'
2018-10-26 @flpvsk @KyivJS 17
Пример
!
--> POST { text: 'I love all' } '/flpvsk/posts'
"
<-- { id: 'addr1' }
#
--> POST { share: 'newId' } '/kickz/posts'
"
<-- { id: …, share: 'newId' }
!
--> PUT { text: 'I hate birds' } '/flpvsk/posts/addr1'
2018-10-26 @flpvsk @KyivJS 17
2018-10-26 @flpvsk @KyivJS 18
2018-10-26 @flpvsk @KyivJS 19
Git как база данных
—Commit, tree, blob – объекты в базе Git
—Объект это файл в .git/objects/${id}
—ID объекта это SHA1 от содержимого
—blob = содержимое файла
2018-10-26 @flpvsk @KyivJS 20
Git
> git init .
> tree .git/objects
objects/
2018-10-26 @flpvsk @KyivJS 21
Git
> git init .
> tree .git/objects
objects/
2018-10-26 @flpvsk @KyivJS 21
Git
> git init .
> tree .git/objects
objects/
2018-10-26 @flpvsk @KyivJS 21
Git
> echo '{ "text": "I love all" }' > newId.json
> git add newId.json
> tree .git/objects
objects/
└── d7
   └── 62b07ccb7fd8ef56f06a72b3b716cfd0c850b0
2018-10-26 @flpvsk @KyivJS 22
Git
> echo '{ "text": "I love all" }' > newId.json
> git add newId.json
> tree .git/objects
objects/
└── d7
   └── 62b07ccb7fd8ef56f06a72b3b716cfd0c850b0
2018-10-26 @flpvsk @KyivJS 22
Git
> echo '{ "text": "I love all" }' > newId.json
> git add newId.json
> tree .git/objects
objects/
└── d7
   └── 62b07ccb7fd8ef56f06a72b3b716cfd0c850b0
2018-10-26 @flpvsk @KyivJS 22
Git
> echo '{ "share": "d762…b0" }' > shareId.json
> git add shareId.json
> tree .git/objects
objects/
├── 6a
│   └── a55922efb726913f2848db03869efc03eea396
└── d7
   └── 62b07ccb7fd8ef56f06a72b3b716cfd0c850b0
2018-10-26 @flpvsk @KyivJS 23
Git
> echo '{ "share": "d762…b0" }' > shareId.json
> git add shareId.json
> tree .git/objects
objects/
├── 6a
│   └── a55922efb726913f2848db03869efc03eea396
└── d7
   └── 62b07ccb7fd8ef56f06a72b3b716cfd0c850b0
2018-10-26 @flpvsk @KyivJS 23
Git
> echo '{ "share": "d762…b0" }' > shareId.json
> git add shareId.json
> tree .git/objects
objects/
├── 6a
│   └── a55922efb726913f2848db03869efc03eea396
└── d7
   └── 62b07ccb7fd8ef56f06a72b3b716cfd0c850b0
2018-10-26 @flpvsk @KyivJS 23
Git
> echo '{ "text": "I hate birds" }' > newId.json
> git add newId.json
> tree .git/objects
objects/
├── 52
│   └── 9b374bb968321f4651d03f74dd38198fabb58b
├── 6a
│   └── a55922efb726913f2848db03869efc03eea396
└── d7
   └── 62b07ccb7fd8ef56f06a72b3b716cfd0c850b0
2018-10-26 @flpvsk @KyivJS 24
Git
> echo '{ "text": "I hate birds" }' > newId.json
> git add newId.json
> tree .git/objects
objects/
├── 52
│   └── 9b374bb968321f4651d03f74dd38198fabb58b
├── 6a
│   └── a55922efb726913f2848db03869efc03eea396
└── d7
   └── 62b07ccb7fd8ef56f06a72b3b716cfd0c850b0
2018-10-26 @flpvsk @KyivJS 24
Git
> echo '{ "text": "I hate birds" }' > newId.json
> git add newId.json
> tree .git/objects
objects/
├── 52
│   └── 9b374bb968321f4651d03f74dd38198fabb58b
├── 6a
│   └── a55922efb726913f2848db03869efc03eea396
└── d7
   └── 62b07ccb7fd8ef56f06a72b3b716cfd0c850b0
2018-10-26 @flpvsk @KyivJS 24
2018-10-26 @flpvsk @KyivJS 25
CouchDB
!
--> POST { text: 'I love all' } '/posts'
"
<-- { id: 'addr1', rev: '1-abc' }
!
--> PUT { text: 'I hate birds', _rev: '1-abc' } '/posts/addr1'
"
<-- { id: 'addr1', rev: '2-bde' }
2018-10-26 @flpvsk @KyivJS 26
CouchDB
!
--> POST { text: 'I love all' } '/posts'
"
<-- { id: 'addr1', rev: '1-abc' }
!
--> PUT { text: 'I hate birds', _rev: '1-abc' } '/posts/addr1'
"
<-- { id: 'addr1', rev: '2-bde' }
2018-10-26 @flpvsk @KyivJS 26
CouchDB
!
--> POST { text: 'I love all' } '/posts'
"
<-- { id: 'addr1', rev: '1-abc' }
!
--> PUT { text: 'I hate birds', _rev: '1-abc' } '/posts/addr1'
"
<-- { id: 'addr1', rev: '2-bde' }
2018-10-26 @flpvsk @KyivJS 26
CouchDB
!
--> POST { text: 'I love all' } '/posts'
"
<-- { id: 'addr1', rev: '1-abc' }
!
--> PUT { text: 'I hate birds', _rev: '1-abc' } '/posts/addr1'
"
<-- { id: 'addr1', rev: '2-bde' }
2018-10-26 @flpvsk @KyivJS 26
Другие проекты
2018-10-26 @flpvsk @KyivJS 27
Другие проекты
—BitTorrent
2018-10-26 @flpvsk @KyivJS 27
Другие проекты
—BitTorrent
—BitCoin
2018-10-26 @flpvsk @KyivJS 27
Другие проекты
—BitTorrent
—BitCoin
—IPFS
2018-10-26 @flpvsk @KyivJS 27
Другие проекты
—BitTorrent
—BitCoin
—IPFS
—Dat
2018-10-26 @flpvsk @KyivJS 27
#3
Состояние /
Операция2018-10-26 @flpvsk @KyivJS 28
Найди три отличия
// State
{ _id: 'cl1+1-2', name: 'Andrey', podcasts: [ 'Code' ] }
// Op
{ $set: { name: 'Andrey' } }
2018-10-26 @flpvsk @KyivJS 29
Состояние и операции
// State
{ _id: 'cl1+1-2', name: 'Andrey', podcasts: [ 'Code' ] }
// Ops
[
{ $set: { name: 'Andrey' } },
{ podcasts: { $add: 'Code' } }
]
2018-10-26 @flpvsk @KyivJS 30
Состояние и операции
// State
{ _id: 'cl1+1-2', name: 'Andrey', podcasts: [ 'Code' ] }
// Ops
[
{ $set: { name: 'Andrey' } },
{ podcasts: { $add: 'Code' } }
]
2018-10-26 @flpvsk @KyivJS 30
Состояние и операции
// State
{ _id: 'cl1+1-2', name: 'Andrey', podcasts: [ 'Code' ] }
// Ops
[
{ _id: 'cl1+1', $set: { name: 'Andrey' } },
{ _id: 'cl1+2', _parent: 'cl1+1', podcasts: { $add: 'Code' } },
]
2018-10-26 @flpvsk @KyivJS 31
Патч
// State 1
{
_id: 'cl1+1-2.cl2+1-2',
name: 'Andrey S',
podcasts: [ 'Code' ],
instruments: [ 'Bass' ],
}
// State 2
{
_id: 'cl1+1-2',
name: 'Andrey',
podcasts: [ 'Code' ]
}
2018-10-26 @flpvsk @KyivJS 32
Патч
// Ops
[
{ _id: 'cl1+1', $set: { name: 'Andrey' } },
{ _id: 'cl1+2', _parent: '1+cl1', podcasts: { $add: 'Code' } },
{ _id: 'cl2+1', $set: { name: 'Andrey S' } },
{ _id: 'cl2+2', _parent: 'cl2+1', instruments: { $add: 'Bass' } },
]
2018-10-26 @flpvsk @KyivJS 33
Патч
// Patch === State
{
_id: 'cl2+1-2',
name: 'Andrey S',
instruments: [ 'Bass' ],
}
2018-10-26 @flpvsk @KyivJS 34
Состояние ~ Патч ~ Лог
операций
2018-10-26 @flpvsk @KyivJS 35
Пример из HeyMoose!
2018-10-26 @flpvsk @KyivJS 36
Другие проекты
2018-10-26 @flpvsk @KyivJS 37
Другие проекты
—RON – replicated object model
2018-10-26 @flpvsk @KyivJS 37
Другие проекты
—RON – replicated object model
—Kafka
2018-10-26 @flpvsk @KyivJS 37
Другие проекты
—RON – replicated object model
—Kafka
—Dat
2018-10-26 @flpvsk @KyivJS 37
Итог
2018-10-26 @flpvsk @KyivJS 38
Итог
—Предположения определяют API
2018-10-26 @flpvsk @KyivJS 38
Итог
—Предположения определяют API
—Изучайте проекты вне вашей специализации
2018-10-26 @flpvsk @KyivJS 38
@flpvsk
codepodcast.com
2018-10-26 @flpvsk @KyivJS 39

Weitere ähnliche Inhalte

Empfohlen

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 

Empfohlen (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

API дизайн: уроки известных проектов, Андрей Саломатин, KievJS