SlideShare ist ein Scribd-Unternehmen logo
1 von 17
How to define
  an API
             Presenter
       Alexandru Chica
Summary
•   What is an API?
•   Properties of an API
•   Guidelines for developing an API
•   API maintenance
•   C/C++ specific APIs
•   Anti-Patterns
•   Conclusion
What is an API?
•   An API is the interface implemented by an
    application which allows other applications to
    communicate with it.

•   An application programming interface (API)
    is a specification intended to be used as an
    interface by software components to
    communicate with each other.
Properties of an API
•   Easy to learn
•   Easy to use
•   Hard to misuse
•   Easy to read and maintain
•   Easy to extend
•   Satisfies requirements
•   Designed for an audience
Guidelines #1
•   An API should do one thing and do it well
    o   Single responsibility principle
•   An API should be as simple as possible
    o   should satisfy requirements
    o   apply KISS (Keep It Simple Stupid)
    o   should be open to extension and closed to
        modification
•   Implementation details should not leak into
    the API
Guidelines #2
•   Minimize accessibility
    o   Encapsulation

•   Proper naming
    o   names should be self-explanatory

    o   naming consistency

    o   one goal should be symmetry

    o   "code should read like prose"
Guidelines #2 - Examples
isNotAvailable() vs isAvailable()
isNull() vs isValid()
getApples(), getRaisins() vs getFruit(Fruit_t )
setValue1(), setValue2(), setValue3() vs
setValue1(), applyValue2(), writeValue3()

if(car.speed() > (2*SPEED_LIMIT))
   generateAlert("Watch out for cops!")
Guidelines #3
•   Documentation
    o   very important!
    o   impacts reusability
           good design without documentation won't be
            reused
    o   documented units:
           class: what the instance represents
           method/function: precondition, postcondition,
            side-effect
           parameter: meaning, ownership
Guidelines #4
•   Performance
    o   depends on the environment
    o   how will the component be used?
           lots of calls/lots of clients
           few calls/few clients
           does it scale? vs does it need to scale?
    o   concurrency
    o   parallelism
•   Logical consistency (naming & behavior)
API Maintenance
•   Versioning

•   Documentation

•   Backward compatibility

•   Usability
•   Extensibility
API Maintenance
•   No API is perfect in the first shot
•   Expect to make mistakes
    o   real-world usage will reveal design mistakes
    o   expect to evolve the API
•   Rule of user opinions: if you have n users
    that use your API you will get n+1
    suggestions to "improve" the API
    o   Fact: you won't be able to please everyone
    o   Suggestion: aim to displease everyone equally
C/C++ Specific APIs
•   Design issues:
    o   Who should allocate?

    o   Type safety

    o   Preprocessor usage

    o   Debugging

    o   Testability

    o   Strings
C/C++ Specific APIs
•   PIMPL
    •   Changing private members does not require
        recompilation of class and dependencies

    •   The header does not need to include dependant
        headers since objects are forward declared  faster
        compile time
Anti-patterns #1
•   Logical inconsistency

    o    Some windows functions that return a HANDLE use
        NULL/0 for an error (CreateThread), some use
        INVALID_HANDLE_VALUE/-1 for an error
        (CreateFile).
    o   pthread_cond_wait in the POSIX pthreads API, is
        actually an unconditional wait
Anti-patterns #2
•   Stringification (##)

•   Defining functions in public header files

•   Not using namespaces (non-C)

•   Writing non-cross-platform code in public
    header files
Conclusion

               The best API is no API




•   The ideal features of an API are those that require no or
    very little code from the application developer.
References
•   http://lcsd05.cs.tamu.edu/slides/keynote.pdf
•   http://chaos.troll.no/~shausman/api-
    design/api-design.pdf

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (17)

Scaling API Design - Nordic APIs 2014
Scaling API Design - Nordic APIs 2014Scaling API Design - Nordic APIs 2014
Scaling API Design - Nordic APIs 2014
 
Scaling API Design
Scaling API DesignScaling API Design
Scaling API Design
 
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessible
 
apidays LIVE Paris - How to build better and consistent APIs at scale by Sami...
apidays LIVE Paris - How to build better and consistent APIs at scale by Sami...apidays LIVE Paris - How to build better and consistent APIs at scale by Sami...
apidays LIVE Paris - How to build better and consistent APIs at scale by Sami...
 
Scaling API Design
Scaling API DesignScaling API Design
Scaling API Design
 
Rest in practice
Rest in practiceRest in practice
Rest in practice
 
apidays LIVE London 2021 - Designing APIs: Less Data is More by Damir Svrtan,...
apidays LIVE London 2021 - Designing APIs: Less Data is More by Damir Svrtan,...apidays LIVE London 2021 - Designing APIs: Less Data is More by Damir Svrtan,...
apidays LIVE London 2021 - Designing APIs: Less Data is More by Damir Svrtan,...
 
YAGNI, YMMV and APIs: building a hybrid strategy for your API platform.
YAGNI, YMMV and APIs: building a hybrid strategy for your API platform.YAGNI, YMMV and APIs: building a hybrid strategy for your API platform.
YAGNI, YMMV and APIs: building a hybrid strategy for your API platform.
 
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
 
apidays LIVE Hong Kong 2021 - Better API DX with a CLI by Phil Nash, Twilio
apidays LIVE Hong Kong 2021 - Better API DX with a CLI by Phil Nash, Twilioapidays LIVE Hong Kong 2021 - Better API DX with a CLI by Phil Nash, Twilio
apidays LIVE Hong Kong 2021 - Better API DX with a CLI by Phil Nash, Twilio
 
What is Swagger?
What is Swagger?What is Swagger?
What is Swagger?
 
Do's and Don'ts of APIs
Do's and Don'ts of APIsDo's and Don'ts of APIs
Do's and Don'ts of APIs
 
Pain Points In API Development? They’re Everywhere
Pain Points In API Development? They’re EverywherePain Points In API Development? They’re Everywhere
Pain Points In API Development? They’re Everywhere
 
Past, Present, Future of APIS
Past, Present, Future of APISPast, Present, Future of APIS
Past, Present, Future of APIS
 
Mulesoft Raml APIs
Mulesoft Raml APIsMulesoft Raml APIs
Mulesoft Raml APIs
 
Moving into API documentation writing
Moving into API documentation writingMoving into API documentation writing
Moving into API documentation writing
 
API Developer Experience: Why it Matters, and How Documenting Your API with S...
API Developer Experience: Why it Matters, and How Documenting Your API with S...API Developer Experience: Why it Matters, and How Documenting Your API with S...
API Developer Experience: Why it Matters, and How Documenting Your API with S...
 

Andere mochten auch

productronica 2013 Tageszeitung Tag 1 / daily newspaper day 1
productronica 2013 Tageszeitung Tag 1 / daily newspaper day 1productronica 2013 Tageszeitung Tag 1 / daily newspaper day 1
productronica 2013 Tageszeitung Tag 1 / daily newspaper day 1
Messe München GmbH
 
17 Aralık 2014 Serap Mutlu Akbulut Konseri Resimleri
17 Aralık 2014 Serap Mutlu Akbulut Konseri Resimleri17 Aralık 2014 Serap Mutlu Akbulut Konseri Resimleri
17 Aralık 2014 Serap Mutlu Akbulut Konseri Resimleri
aokutur
 
Levi student consil
Levi student consilLevi student consil
Levi student consil
Durke1dd
 
Citrex610 l-en-spa 3 citrex directo en alimentos(2)
Citrex610 l-en-spa 3 citrex directo en alimentos(2)Citrex610 l-en-spa 3 citrex directo en alimentos(2)
Citrex610 l-en-spa 3 citrex directo en alimentos(2)
CITREX
 

Andere mochten auch (20)

The Groovy Way
The Groovy WayThe Groovy Way
The Groovy Way
 
The Future of Cloud Innovation, featuring Adrian Cockcroft
The Future of Cloud Innovation, featuring Adrian CockcroftThe Future of Cloud Innovation, featuring Adrian Cockcroft
The Future of Cloud Innovation, featuring Adrian Cockcroft
 
Non functional requirements framework
Non functional requirements frameworkNon functional requirements framework
Non functional requirements framework
 
Performance Testing REST APIs
Performance Testing REST APIsPerformance Testing REST APIs
Performance Testing REST APIs
 
Yow Conference Dec 2013 Netflix Workshop Slides with Notes
Yow Conference Dec 2013 Netflix Workshop Slides with NotesYow Conference Dec 2013 Netflix Workshop Slides with Notes
Yow Conference Dec 2013 Netflix Workshop Slides with Notes
 
Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016
 
Monitorama 2015 Netflix Instance Analysis
Monitorama 2015 Netflix Instance AnalysisMonitorama 2015 Netflix Instance Analysis
Monitorama 2015 Netflix Instance Analysis
 
KPIs for APIs (and how API Calls are the new Web Hits, and you may be measuri...
KPIs for APIs (and how API Calls are the new Web Hits, and you may be measuri...KPIs for APIs (and how API Calls are the new Web Hits, and you may be measuri...
KPIs for APIs (and how API Calls are the new Web Hits, and you may be measuri...
 
Дамир Халилов_ Эффективное продвижение во ВКонтакте.ру и Facebook
Дамир Халилов_ Эффективное продвижение во ВКонтакте.ру и FacebookДамир Халилов_ Эффективное продвижение во ВКонтакте.ру и Facebook
Дамир Халилов_ Эффективное продвижение во ВКонтакте.ру и Facebook
 
Михеев Юрий - Применение современных инструментов интегрированного менеджмент...
Михеев Юрий - Применение современных инструментов интегрированного менеджмент...Михеев Юрий - Применение современных инструментов интегрированного менеджмент...
Михеев Юрий - Применение современных инструментов интегрированного менеджмент...
 
productronica 2013 Tageszeitung Tag 1 / daily newspaper day 1
productronica 2013 Tageszeitung Tag 1 / daily newspaper day 1productronica 2013 Tageszeitung Tag 1 / daily newspaper day 1
productronica 2013 Tageszeitung Tag 1 / daily newspaper day 1
 
Ospmi Chapter Presentation
Ospmi Chapter PresentationOspmi Chapter Presentation
Ospmi Chapter Presentation
 
17 Aralık 2014 Serap Mutlu Akbulut Konseri Resimleri
17 Aralık 2014 Serap Mutlu Akbulut Konseri Resimleri17 Aralık 2014 Serap Mutlu Akbulut Konseri Resimleri
17 Aralık 2014 Serap Mutlu Akbulut Konseri Resimleri
 
Levi student consil
Levi student consilLevi student consil
Levi student consil
 
BabbleLABEL [Web Ready 2010]
BabbleLABEL [Web Ready 2010]BabbleLABEL [Web Ready 2010]
BabbleLABEL [Web Ready 2010]
 
Bio181 spring11
Bio181 spring11Bio181 spring11
Bio181 spring11
 
Ingria games Joybits
Ingria games JoybitsIngria games Joybits
Ingria games Joybits
 
Citrex610 l-en-spa 3 citrex directo en alimentos(2)
Citrex610 l-en-spa 3 citrex directo en alimentos(2)Citrex610 l-en-spa 3 citrex directo en alimentos(2)
Citrex610 l-en-spa 3 citrex directo en alimentos(2)
 
Inbound Marketing - Promotion
Inbound Marketing - PromotionInbound Marketing - Promotion
Inbound Marketing - Promotion
 
Механизмы государственной поддержки экспортно-ориентированных субъектов малог...
Механизмы государственной поддержки экспортно-ориентированных субъектов малог...Механизмы государственной поддержки экспортно-ориентированных субъектов малог...
Механизмы государственной поддержки экспортно-ориентированных субъектов малог...
 

Ähnlich wie How to define an api

How to design good api
How to design good apiHow to design good api
How to design good api
Osama Shakir
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
rsebbe
 
How To Design A Good A P I And Why It Matters G O O G L E
How To Design A Good  A P I And Why It Matters    G O O G L EHow To Design A Good  A P I And Why It Matters    G O O G L E
How To Design A Good A P I And Why It Matters G O O G L E
guestbe92f4
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
NLJUG
 

Ähnlich wie How to define an api (20)

API Design - developing for developers
API Design - developing for developersAPI Design - developing for developers
API Design - developing for developers
 
How to design good api
How to design good apiHow to design good api
How to design good api
 
INTERFACE by apidays 2023 - API Design Governance, Nauman Ali, Stoplight
INTERFACE by apidays 2023 - API Design Governance, Nauman Ali, StoplightINTERFACE by apidays 2023 - API Design Governance, Nauman Ali, Stoplight
INTERFACE by apidays 2023 - API Design Governance, Nauman Ali, Stoplight
 
Angular 2
Angular 2Angular 2
Angular 2
 
Practices and Tools for Building Better APIs
Practices and Tools for Building Better APIsPractices and Tools for Building Better APIs
Practices and Tools for Building Better APIs
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
Building a REST API for Longevity
Building a REST API for LongevityBuilding a REST API for Longevity
Building a REST API for Longevity
 
REST-API's for architects and managers
REST-API's for architects and managersREST-API's for architects and managers
REST-API's for architects and managers
 
API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)
 
apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...
apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...
apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...
 
Keynoteof A P I
Keynoteof A P IKeynoteof A P I
Keynoteof A P I
 
Revamping Mailjet API documentation @ ParisAPI meetup
Revamping Mailjet API documentation @ ParisAPI meetupRevamping Mailjet API documentation @ ParisAPI meetup
Revamping Mailjet API documentation @ ParisAPI meetup
 
How to design effective APIs
How to design effective APIsHow to design effective APIs
How to design effective APIs
 
How To Design A Good A P I And Why It Matters G O O G L E
How To Design A Good  A P I And Why It Matters    G O O G L EHow To Design A Good  A P I And Why It Matters    G O O G L E
How To Design A Good A P I And Why It Matters G O O G L E
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
 
Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)
 
Always up to date, testable and maintainable documentation with OpenAPI
Always up to date, testable and maintainable documentation with OpenAPIAlways up to date, testable and maintainable documentation with OpenAPI
Always up to date, testable and maintainable documentation with OpenAPI
 
How aspects clean your code
How aspects clean your codeHow aspects clean your code
How aspects clean your code
 
API presentation
API presentationAPI presentation
API presentation
 
Auckland API & Microservices Meetup 1: API led design
Auckland API & Microservices Meetup 1: API led designAuckland API & Microservices Meetup 1: API led design
Auckland API & Microservices Meetup 1: API led design
 

How to define an api

  • 1. How to define an API Presenter Alexandru Chica
  • 2. Summary • What is an API? • Properties of an API • Guidelines for developing an API • API maintenance • C/C++ specific APIs • Anti-Patterns • Conclusion
  • 3. What is an API? • An API is the interface implemented by an application which allows other applications to communicate with it. • An application programming interface (API) is a specification intended to be used as an interface by software components to communicate with each other.
  • 4. Properties of an API • Easy to learn • Easy to use • Hard to misuse • Easy to read and maintain • Easy to extend • Satisfies requirements • Designed for an audience
  • 5. Guidelines #1 • An API should do one thing and do it well o Single responsibility principle • An API should be as simple as possible o should satisfy requirements o apply KISS (Keep It Simple Stupid) o should be open to extension and closed to modification • Implementation details should not leak into the API
  • 6. Guidelines #2 • Minimize accessibility o Encapsulation • Proper naming o names should be self-explanatory o naming consistency o one goal should be symmetry o "code should read like prose"
  • 7. Guidelines #2 - Examples isNotAvailable() vs isAvailable() isNull() vs isValid() getApples(), getRaisins() vs getFruit(Fruit_t ) setValue1(), setValue2(), setValue3() vs setValue1(), applyValue2(), writeValue3() if(car.speed() > (2*SPEED_LIMIT)) generateAlert("Watch out for cops!")
  • 8. Guidelines #3 • Documentation o very important! o impacts reusability  good design without documentation won't be reused o documented units:  class: what the instance represents  method/function: precondition, postcondition, side-effect  parameter: meaning, ownership
  • 9. Guidelines #4 • Performance o depends on the environment o how will the component be used?  lots of calls/lots of clients  few calls/few clients  does it scale? vs does it need to scale? o concurrency o parallelism • Logical consistency (naming & behavior)
  • 10. API Maintenance • Versioning • Documentation • Backward compatibility • Usability • Extensibility
  • 11. API Maintenance • No API is perfect in the first shot • Expect to make mistakes o real-world usage will reveal design mistakes o expect to evolve the API • Rule of user opinions: if you have n users that use your API you will get n+1 suggestions to "improve" the API o Fact: you won't be able to please everyone o Suggestion: aim to displease everyone equally
  • 12. C/C++ Specific APIs • Design issues: o Who should allocate? o Type safety o Preprocessor usage o Debugging o Testability o Strings
  • 13. C/C++ Specific APIs • PIMPL • Changing private members does not require recompilation of class and dependencies • The header does not need to include dependant headers since objects are forward declared  faster compile time
  • 14. Anti-patterns #1 • Logical inconsistency o Some windows functions that return a HANDLE use NULL/0 for an error (CreateThread), some use INVALID_HANDLE_VALUE/-1 for an error (CreateFile). o pthread_cond_wait in the POSIX pthreads API, is actually an unconditional wait
  • 15. Anti-patterns #2 • Stringification (##) • Defining functions in public header files • Not using namespaces (non-C) • Writing non-cross-platform code in public header files
  • 16. Conclusion The best API is no API • The ideal features of an API are those that require no or very little code from the application developer.
  • 17. References • http://lcsd05.cs.tamu.edu/slides/keynote.pdf • http://chaos.troll.no/~shausman/api- design/api-design.pdf