APIs Flashcards
1
Q
GET
A
Read
http://www.example.com/customers/12345/orders
2
Q
PUT
A
Update/Replace
http://www.example.com/customers/12345/orders/98765
3
Q
PATCH
A
Update/Modify
http://www.example.com/customers/12345/orders/98765
4
Q
DELETE
A
Delete
http://www.example.com/customers/12345/orders
5
Q
POST
A
Create
http://www.example.com/customers/12345/orders
6
Q
Principles of Good API Design
A
- Do one thing and do it well
- APIs should be as small as possible because it can be difficult to remove features. Conceptual weight is more important than supporting a lot of endpoints. Think about it in terms of power to weight ratio.
- Don’t let implementation details leak into the API. (e.g.. on disk and serialization formats, tuning parameters.)
- Maximize information hiding so modules can be built, tested, and debugged separately
- Choose names carefully and be consistent
- Re-use requires good design and good documentation
7
Q
Performance Consequences of Poor API Design
A
Bad
- Making types mutable
- Providing a constructor instead of static factory. (Static factories are not required to create a new object every time they are called. Prevents the creation of unnecessary objects.)
- Using a concrete implementation type instead of an interface
- Example: Component.getSize() returns a dimension that is mutable. That means each call much create a new Dimension object, which results in millions of needless object allocations.