SlideShare a Scribd company logo
1 of 20
Download to read offline
Part 3 Fundamentals
9. Custom methods
Rick Hwang
2022/04/20
1
How to safely support these actions on resources in a web
API while maintaining a simple, predictable, and functional
API using what we’ll call custom methods.
2
Recap
3
9.1 Motivation
1. when we need the ability to express a specific action that doesn’t really fit
very well in one of the standard methods (ch7).
2. how to integrate to current systems or framework:
○ should we try to jam the behavior we want into the existing methods, bending the framework a
bit to fit our needs? Or
○ should we change our behavior into a form that fits a bit more cleanly within the framework?
Or
○ should we change the framework to accommodate our new scenario?
4
1
2.1
2.2
5
Two resources:
1. EmailDraft
2. Email
---
6
1. most state changes are transitions of some sort or another, and as a result,
transitioning to a new state is fundamentally different from setting the value of
a scalar field.
a. This field feels like it should be managed by the API service itself rather than updated by the
client.
b. 狀態 (State) 的改變 (transition) 應該由 Service 管理,不是 POST 過來
2. As we learned in chapter 7, standard methods really should NOT do anything
besides the specific action their name implies.
7
9.2 Overview
Custom methods are nothing
more than API calls that fall
outside the scope of a standard
method.
8
9.3 Implementation
1. 不要使用 farword slash (/) 作動詞區隔,像是 POST /rockets/1234567/launch (這很重
要)
a. Rick: 哪裡重要?
2. RPC 遵循規則: 動詞 + 名詞,像是 LaunchRocket or ArchiveDocument,避免使用 With / For 等
介系詞。
9
10
11
9.3.1 Side Effects
Standard Methods
1. 針對能操作的資源,提供 有限制的機制
2. Standard Method 之外,沒有其他行為 (理
論上)
Custom Methods
1. 針對能操作的資源,提供 有彈性的機制
2. 依照 Standard Method 的行為之外,可以
表述其他行為,像是 觸發 額外的背景操作
舉例:1) CreateEmail -> 2) SendEmal
12
5.1 Load EmailDraft
from Storage
使用 Custom Method:
處理複雜的行為,像是與另外
的系統通訊 (SMTP)
同時處理 Resources and
Collections
使用 Standard Method:
單純、簡單
13
9.3.2 Resources vs Collections
某一個人的某一
封 Email
某一個人的全部
14
匯出單一 User 的所有 Email (General Users),
or
一個操作執行多個資源操作:
ex: 使用一個 API 匯出一堆 Email (Admin)
以下都是匯出多個資源。。。
1) POST /users/1:exportEmails
2) POST /users/1/emails:export
3) POST /users/1:export
哪個好?
更多參
閱
Ch23
15
針對跨 Users 的 Email 進行操作,像是 archive / export
● users/1/emails/2:export
● users/2/emails/4:export
使用 hyphon 當作 Wildcard 代表使用者。
POST /users/-/emails:export
{
“1”: [2],
“2”: [4],
}
更多參
閱
Ch23
16
9.3.3 Stateless
custom methods
17
Stateful custom
methods
18
9.4 Trade-offs
the very existence of these custom methods tends to present a contradiction (矛
盾) with REST and the principles underpinning RESTful API design.
19
Summary
1. Custom methods should almost always use the HTTP POST method and never use the
PATCH method. They might use the GET method if the custom method is idempotent and
safe.
2. Custom methods use a colon (:) character to separate the resource target from the action
being performed (e.g., /missiles/1234:launch).
3. While side effects are forbidden for standard methods, they are permitted for custom
methods. They should be used sparingly and documented thoroughly to avoid confusion for
users.
4. In general, custom methods should target a collection when multiple resources from a
single collection are involved.
5. Sometimes, particularly for computational work, APIs might choose to rely on stateless
custom methods to perform the bulk of the work. This strategy should be used cautiously as
it’s easy for statefulness to eventually become important and can be difficult to introduce
later on.
20

More Related Content

Similar to Fundamentals 9. Custom methods

Step by-step cloud migration checklist
Step by-step cloud migration checklist Step by-step cloud migration checklist
Step by-step cloud migration checklist Forte Group
 
IRJET- Amazon Redshift Workload Management and Fast Retrieval of Data
IRJET- Amazon Redshift Workload Management and Fast Retrieval of DataIRJET- Amazon Redshift Workload Management and Fast Retrieval of Data
IRJET- Amazon Redshift Workload Management and Fast Retrieval of DataIRJET Journal
 
Reactive Performance Testing
Reactive Performance TestingReactive Performance Testing
Reactive Performance TestingLilit Yenokyan
 
Migration to the cloud
Migration to the cloudMigration to the cloud
Migration to the cloudEPAM Systems
 
Software engineering Questions and Answers
Software engineering Questions and AnswersSoftware engineering Questions and Answers
Software engineering Questions and AnswersBala Ganesh
 
Workload-Aware: Auto-Scaling A new paradigm for Big Data Workloads
Workload-Aware: Auto-Scaling A new paradigm for Big Data WorkloadsWorkload-Aware: Auto-Scaling A new paradigm for Big Data Workloads
Workload-Aware: Auto-Scaling A new paradigm for Big Data WorkloadsVasu S
 
Performance and load testing
Performance and load testingPerformance and load testing
Performance and load testingsonukalpana
 
Gomez Blazing Fast Cloud Best Practices
Gomez Blazing Fast Cloud Best Practices Gomez Blazing Fast Cloud Best Practices
Gomez Blazing Fast Cloud Best Practices Compuware APM
 
Hibernate interview questions
Hibernate interview questionsHibernate interview questions
Hibernate interview questionsvenkata52
 
Client Server Model and Distributed Computing
Client Server Model and Distributed ComputingClient Server Model and Distributed Computing
Client Server Model and Distributed ComputingAbhishek Jaisingh
 
Understanding_the_Cloud
Understanding_the_CloudUnderstanding_the_Cloud
Understanding_the_CloudMelissa Kattke
 
12 couplingand cohesion-student
12 couplingand cohesion-student12 couplingand cohesion-student
12 couplingand cohesion-studentrandhirlpu
 
Amplitude wave architecture - Test
Amplitude wave architecture - TestAmplitude wave architecture - Test
Amplitude wave architecture - TestKiran Naiga
 
Software architecture case study - why and why not sql server replication
Software architecture   case study - why and why not sql server replicationSoftware architecture   case study - why and why not sql server replication
Software architecture case study - why and why not sql server replicationShahzad
 
EMC Documentum Compliance Manager Migration Revisited — What a Difference Two...
EMC Documentum Compliance Manager Migration Revisited — What a Difference Two...EMC Documentum Compliance Manager Migration Revisited — What a Difference Two...
EMC Documentum Compliance Manager Migration Revisited — What a Difference Two...BlueFish
 
Navigating the Cloud: Empowering Enterprises with Cloud Solutions
Navigating the Cloud: Empowering Enterprises with Cloud SolutionsNavigating the Cloud: Empowering Enterprises with Cloud Solutions
Navigating the Cloud: Empowering Enterprises with Cloud SolutionsMaryJWilliams2
 

Similar to Fundamentals 9. Custom methods (20)

Step by-step cloud migration checklist
Step by-step cloud migration checklist Step by-step cloud migration checklist
Step by-step cloud migration checklist
 
Rails interview questions
Rails interview questionsRails interview questions
Rails interview questions
 
IRJET- Amazon Redshift Workload Management and Fast Retrieval of Data
IRJET- Amazon Redshift Workload Management and Fast Retrieval of DataIRJET- Amazon Redshift Workload Management and Fast Retrieval of Data
IRJET- Amazon Redshift Workload Management and Fast Retrieval of Data
 
Reactive Performance Testing
Reactive Performance TestingReactive Performance Testing
Reactive Performance Testing
 
Migration to the cloud
Migration to the cloudMigration to the cloud
Migration to the cloud
 
Software engineering Questions and Answers
Software engineering Questions and AnswersSoftware engineering Questions and Answers
Software engineering Questions and Answers
 
Workload-Aware: Auto-Scaling A new paradigm for Big Data Workloads
Workload-Aware: Auto-Scaling A new paradigm for Big Data WorkloadsWorkload-Aware: Auto-Scaling A new paradigm for Big Data Workloads
Workload-Aware: Auto-Scaling A new paradigm for Big Data Workloads
 
Data dayposter v1.2
Data dayposter v1.2Data dayposter v1.2
Data dayposter v1.2
 
Performance and load testing
Performance and load testingPerformance and load testing
Performance and load testing
 
Gomez Blazing Fast Cloud Best Practices
Gomez Blazing Fast Cloud Best Practices Gomez Blazing Fast Cloud Best Practices
Gomez Blazing Fast Cloud Best Practices
 
Hibernate interview questions
Hibernate interview questionsHibernate interview questions
Hibernate interview questions
 
Client Server Model and Distributed Computing
Client Server Model and Distributed ComputingClient Server Model and Distributed Computing
Client Server Model and Distributed Computing
 
Understanding_the_Cloud
Understanding_the_CloudUnderstanding_the_Cloud
Understanding_the_Cloud
 
12 couplingand cohesion-student
12 couplingand cohesion-student12 couplingand cohesion-student
12 couplingand cohesion-student
 
Grails Services
Grails ServicesGrails Services
Grails Services
 
About HTTP and REST
About HTTP and RESTAbout HTTP and REST
About HTTP and REST
 
Amplitude wave architecture - Test
Amplitude wave architecture - TestAmplitude wave architecture - Test
Amplitude wave architecture - Test
 
Software architecture case study - why and why not sql server replication
Software architecture   case study - why and why not sql server replicationSoftware architecture   case study - why and why not sql server replication
Software architecture case study - why and why not sql server replication
 
EMC Documentum Compliance Manager Migration Revisited — What a Difference Two...
EMC Documentum Compliance Manager Migration Revisited — What a Difference Two...EMC Documentum Compliance Manager Migration Revisited — What a Difference Two...
EMC Documentum Compliance Manager Migration Revisited — What a Difference Two...
 
Navigating the Cloud: Empowering Enterprises with Cloud Solutions
Navigating the Cloud: Empowering Enterprises with Cloud SolutionsNavigating the Cloud: Empowering Enterprises with Cloud Solutions
Navigating the Cloud: Empowering Enterprises with Cloud Solutions
 

More from Rick Hwang

在生命轉彎的地方 - 從軟體開發職涯,探索人生
在生命轉彎的地方 - 從軟體開發職涯,探索人生在生命轉彎的地方 - 從軟體開發職涯,探索人生
在生命轉彎的地方 - 從軟體開發職涯,探索人生Rick Hwang
 
20230829 - 探索職涯,複利人生
20230829 - 探索職涯,複利人生20230829 - 探索職涯,複利人生
20230829 - 探索職涯,複利人生Rick Hwang
 
2023 08 - SRE 實踐與開發平台指南 - 書友見面會
2023 08 - SRE 實踐與開發平台指南 - 書友見面會2023 08 - SRE 實踐與開發平台指南 - 書友見面會
2023 08 - SRE 實踐與開發平台指南 - 書友見面會Rick Hwang
 
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)Rick Hwang
 
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大Rick Hwang
 
CH02 API Governance
CH02 API Governance CH02 API Governance
CH02 API Governance Rick Hwang
 
Chapter 8. Partial updates and retrievals.pdf
Chapter 8. Partial updates and retrievals.pdfChapter 8. Partial updates and retrievals.pdf
Chapter 8. Partial updates and retrievals.pdfRick Hwang
 
AWS Career Exploration Day
AWS Career Exploration DayAWS Career Exploration Day
AWS Career Exploration DayRick Hwang
 
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)Rick Hwang
 
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路Rick Hwang
 
導讀持續交付 2.0 - CH02 價值探索環
導讀持續交付 2.0 - CH02 價值探索環 導讀持續交付 2.0 - CH02 價值探索環
導讀持續交付 2.0 - CH02 價值探索環 Rick Hwang
 
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構Rick Hwang
 
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)Rick Hwang
 
Software Development Process v1.5 - 20121214
Software Development Process v1.5 - 20121214Software Development Process v1.5 - 20121214
Software Development Process v1.5 - 20121214Rick Hwang
 
第三章 建立良好的人際關係網路
第三章 建立良好的人際關係網路第三章 建立良好的人際關係網路
第三章 建立良好的人際關係網路Rick Hwang
 
Wiki in Teamroom - Connected Mind
Wiki in Teamroom - Connected MindWiki in Teamroom - Connected Mind
Wiki in Teamroom - Connected MindRick Hwang
 
導讀持續交付 2.0 - 談當代軟體交付之虛實融合
導讀持續交付 2.0 - 談當代軟體交付之虛實融合導讀持續交付 2.0 - 談當代軟體交付之虛實融合
導讀持續交付 2.0 - 談當代軟體交付之虛實融合Rick Hwang
 
Study Notes - Event-Driven Data Management for Microservices
Study Notes - Event-Driven Data Management for MicroservicesStudy Notes - Event-Driven Data Management for Microservices
Study Notes - Event-Driven Data Management for MicroservicesRick Hwang
 
Study Notes - Using an API Gateway
Study Notes - Using an API GatewayStudy Notes - Using an API Gateway
Study Notes - Using an API GatewayRick Hwang
 
從緊急事件 談 SRE 應變能力的培養 - DevOpsDays Taipei 2018
從緊急事件  談 SRE 應變能力的培養 - DevOpsDays Taipei 2018從緊急事件  談 SRE 應變能力的培養 - DevOpsDays Taipei 2018
從緊急事件 談 SRE 應變能力的培養 - DevOpsDays Taipei 2018Rick Hwang
 

More from Rick Hwang (20)

在生命轉彎的地方 - 從軟體開發職涯,探索人生
在生命轉彎的地方 - 從軟體開發職涯,探索人生在生命轉彎的地方 - 從軟體開發職涯,探索人生
在生命轉彎的地方 - 從軟體開發職涯,探索人生
 
20230829 - 探索職涯,複利人生
20230829 - 探索職涯,複利人生20230829 - 探索職涯,複利人生
20230829 - 探索職涯,複利人生
 
2023 08 - SRE 實踐與開發平台指南 - 書友見面會
2023 08 - SRE 實踐與開發平台指南 - 書友見面會2023 08 - SRE 實踐與開發平台指南 - 書友見面會
2023 08 - SRE 實踐與開發平台指南 - 書友見面會
 
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)
 
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大
 
CH02 API Governance
CH02 API Governance CH02 API Governance
CH02 API Governance
 
Chapter 8. Partial updates and retrievals.pdf
Chapter 8. Partial updates and retrievals.pdfChapter 8. Partial updates and retrievals.pdf
Chapter 8. Partial updates and retrievals.pdf
 
AWS Career Exploration Day
AWS Career Exploration DayAWS Career Exploration Day
AWS Career Exploration Day
 
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
 
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路
 
導讀持續交付 2.0 - CH02 價值探索環
導讀持續交付 2.0 - CH02 價值探索環 導讀持續交付 2.0 - CH02 價值探索環
導讀持續交付 2.0 - CH02 價值探索環
 
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構
 
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)
 
Software Development Process v1.5 - 20121214
Software Development Process v1.5 - 20121214Software Development Process v1.5 - 20121214
Software Development Process v1.5 - 20121214
 
第三章 建立良好的人際關係網路
第三章 建立良好的人際關係網路第三章 建立良好的人際關係網路
第三章 建立良好的人際關係網路
 
Wiki in Teamroom - Connected Mind
Wiki in Teamroom - Connected MindWiki in Teamroom - Connected Mind
Wiki in Teamroom - Connected Mind
 
導讀持續交付 2.0 - 談當代軟體交付之虛實融合
導讀持續交付 2.0 - 談當代軟體交付之虛實融合導讀持續交付 2.0 - 談當代軟體交付之虛實融合
導讀持續交付 2.0 - 談當代軟體交付之虛實融合
 
Study Notes - Event-Driven Data Management for Microservices
Study Notes - Event-Driven Data Management for MicroservicesStudy Notes - Event-Driven Data Management for Microservices
Study Notes - Event-Driven Data Management for Microservices
 
Study Notes - Using an API Gateway
Study Notes - Using an API GatewayStudy Notes - Using an API Gateway
Study Notes - Using an API Gateway
 
從緊急事件 談 SRE 應變能力的培養 - DevOpsDays Taipei 2018
從緊急事件  談 SRE 應變能力的培養 - DevOpsDays Taipei 2018從緊急事件  談 SRE 應變能力的培養 - DevOpsDays Taipei 2018
從緊急事件 談 SRE 應變能力的培養 - DevOpsDays Taipei 2018
 

Recently uploaded

Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 

Recently uploaded (20)

🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 

Fundamentals 9. Custom methods

  • 1. Part 3 Fundamentals 9. Custom methods Rick Hwang 2022/04/20 1
  • 2. How to safely support these actions on resources in a web API while maintaining a simple, predictable, and functional API using what we’ll call custom methods. 2
  • 4. 9.1 Motivation 1. when we need the ability to express a specific action that doesn’t really fit very well in one of the standard methods (ch7). 2. how to integrate to current systems or framework: ○ should we try to jam the behavior we want into the existing methods, bending the framework a bit to fit our needs? Or ○ should we change our behavior into a form that fits a bit more cleanly within the framework? Or ○ should we change the framework to accommodate our new scenario? 4
  • 7. 1. most state changes are transitions of some sort or another, and as a result, transitioning to a new state is fundamentally different from setting the value of a scalar field. a. This field feels like it should be managed by the API service itself rather than updated by the client. b. 狀態 (State) 的改變 (transition) 應該由 Service 管理,不是 POST 過來 2. As we learned in chapter 7, standard methods really should NOT do anything besides the specific action their name implies. 7
  • 8. 9.2 Overview Custom methods are nothing more than API calls that fall outside the scope of a standard method. 8
  • 9. 9.3 Implementation 1. 不要使用 farword slash (/) 作動詞區隔,像是 POST /rockets/1234567/launch (這很重 要) a. Rick: 哪裡重要? 2. RPC 遵循規則: 動詞 + 名詞,像是 LaunchRocket or ArchiveDocument,避免使用 With / For 等 介系詞。 9
  • 10. 10
  • 11. 11
  • 12. 9.3.1 Side Effects Standard Methods 1. 針對能操作的資源,提供 有限制的機制 2. Standard Method 之外,沒有其他行為 (理 論上) Custom Methods 1. 針對能操作的資源,提供 有彈性的機制 2. 依照 Standard Method 的行為之外,可以 表述其他行為,像是 觸發 額外的背景操作 舉例:1) CreateEmail -> 2) SendEmal 12
  • 13. 5.1 Load EmailDraft from Storage 使用 Custom Method: 處理複雜的行為,像是與另外 的系統通訊 (SMTP) 同時處理 Resources and Collections 使用 Standard Method: 單純、簡單 13
  • 14. 9.3.2 Resources vs Collections 某一個人的某一 封 Email 某一個人的全部 14
  • 15. 匯出單一 User 的所有 Email (General Users), or 一個操作執行多個資源操作: ex: 使用一個 API 匯出一堆 Email (Admin) 以下都是匯出多個資源。。。 1) POST /users/1:exportEmails 2) POST /users/1/emails:export 3) POST /users/1:export 哪個好? 更多參 閱 Ch23 15
  • 16. 針對跨 Users 的 Email 進行操作,像是 archive / export ● users/1/emails/2:export ● users/2/emails/4:export 使用 hyphon 當作 Wildcard 代表使用者。 POST /users/-/emails:export { “1”: [2], “2”: [4], } 更多參 閱 Ch23 16
  • 19. 9.4 Trade-offs the very existence of these custom methods tends to present a contradiction (矛 盾) with REST and the principles underpinning RESTful API design. 19
  • 20. Summary 1. Custom methods should almost always use the HTTP POST method and never use the PATCH method. They might use the GET method if the custom method is idempotent and safe. 2. Custom methods use a colon (:) character to separate the resource target from the action being performed (e.g., /missiles/1234:launch). 3. While side effects are forbidden for standard methods, they are permitted for custom methods. They should be used sparingly and documented thoroughly to avoid confusion for users. 4. In general, custom methods should target a collection when multiple resources from a single collection are involved. 5. Sometimes, particularly for computational work, APIs might choose to rely on stateless custom methods to perform the bulk of the work. This strategy should be used cautiously as it’s easy for statefulness to eventually become important and can be difficult to introduce later on. 20