SlideShare a Scribd company logo
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

More Related Content

What's hot (17)

PPTX
Scaling API Design - Nordic APIs 2014
Jason Harmon
 
PPTX
Scaling API Design
Jason Harmon
 
PPTX
Swagger - make your API accessible
Victor Trakhtenberg
 
PDF
apidays LIVE Paris - How to build better and consistent APIs at scale by Sami...
apidays
 
PPTX
Scaling API Design
Jason Harmon
 
PPTX
Rest in practice
Ian Brennan
 
PDF
apidays LIVE London 2021 - Designing APIs: Less Data is More by Damir Svrtan,...
apidays
 
PDF
YAGNI, YMMV and APIs: building a hybrid strategy for your API platform.
Diogo Lucas
 
PDF
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
Open API Initiative (OAI)
 
PDF
apidays LIVE Hong Kong 2021 - Better API DX with a CLI by Phil Nash, Twilio
apidays
 
PPTX
What is Swagger?
Philip Senger
 
PPTX
Do's and Don'ts of APIs
Jason Harmon
 
PPTX
Pain Points In API Development? They’re Everywhere
Nordic APIs
 
PPTX
Past, Present, Future of APIS
Jason Harmon
 
ODP
Mulesoft Raml APIs
akshay yeluru
 
PDF
Moving into API documentation writing
Ellis Pratt
 
PDF
API Developer Experience: Why it Matters, and How Documenting Your API with S...
SmartBear
 
Scaling API Design - Nordic APIs 2014
Jason Harmon
 
Scaling API Design
Jason Harmon
 
Swagger - make your API accessible
Victor Trakhtenberg
 
apidays LIVE Paris - How to build better and consistent APIs at scale by Sami...
apidays
 
Scaling API Design
Jason Harmon
 
Rest in practice
Ian Brennan
 
apidays LIVE London 2021 - Designing APIs: Less Data is More by Damir Svrtan,...
apidays
 
YAGNI, YMMV and APIs: building a hybrid strategy for your API platform.
Diogo Lucas
 
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
Open API Initiative (OAI)
 
apidays LIVE Hong Kong 2021 - Better API DX with a CLI by Phil Nash, Twilio
apidays
 
What is Swagger?
Philip Senger
 
Do's and Don'ts of APIs
Jason Harmon
 
Pain Points In API Development? They’re Everywhere
Nordic APIs
 
Past, Present, Future of APIS
Jason Harmon
 
Mulesoft Raml APIs
akshay yeluru
 
Moving into API documentation writing
Ellis Pratt
 
API Developer Experience: Why it Matters, and How Documenting Your API with S...
SmartBear
 

Viewers also liked (20)

PDF
The Groovy Way
Gabriel Dogaru
 
PDF
The Future of Cloud Innovation, featuring Adrian Cockcroft
Dun & Bradstreet Cloud Innovation Center
 
DOC
Non functional requirements framework
wweinmeyer79
 
PPTX
Performance Testing REST APIs
Jason Weden
 
PPTX
Yow Conference Dec 2013 Netflix Workshop Slides with Notes
Adrian Cockcroft
 
PDF
Microservices Workshop All Topics Deck 2016
Adrian Cockcroft
 
PDF
Monitorama 2015 Netflix Instance Analysis
Brendan Gregg
 
PDF
KPIs for APIs (and how API Calls are the new Web Hits, and you may be measuri...
John Musser
 
PPT
Дамир Халилов_ Эффективное продвижение во ВКонтакте.ру и Facebook
Ingria. Technopark St. Petersburg
 
PDF
Михеев Юрий - Применение современных инструментов интегрированного менеджмент...
Ingria. Technopark St. Petersburg
 
PDF
productronica 2013 Tageszeitung Tag 1 / daily newspaper day 1
Messe München GmbH
 
PDF
Ospmi Chapter Presentation
Dennis Bolles
 
PDF
17 Aralık 2014 Serap Mutlu Akbulut Konseri Resimleri
aokutur
 
PPTX
Levi student consil
Durke1dd
 
PPTX
BabbleLABEL [Web Ready 2010]
Ingria. Technopark St. Petersburg
 
PPTX
Bio181 spring11
Danielle Carlock
 
PPT
Ingria games Joybits
Ingria. Technopark St. Petersburg
 
PPT
Citrex610 l-en-spa 3 citrex directo en alimentos(2)
CITREX
 
PPTX
Inbound Marketing - Promotion
Liberty Digital Marketing
 
PDF
Механизмы государственной поддержки экспортно-ориентированных субъектов малог...
Ingria. Technopark St. Petersburg
 
The Groovy Way
Gabriel Dogaru
 
The Future of Cloud Innovation, featuring Adrian Cockcroft
Dun & Bradstreet Cloud Innovation Center
 
Non functional requirements framework
wweinmeyer79
 
Performance Testing REST APIs
Jason Weden
 
Yow Conference Dec 2013 Netflix Workshop Slides with Notes
Adrian Cockcroft
 
Microservices Workshop All Topics Deck 2016
Adrian Cockcroft
 
Monitorama 2015 Netflix Instance Analysis
Brendan Gregg
 
KPIs for APIs (and how API Calls are the new Web Hits, and you may be measuri...
John Musser
 
Дамир Халилов_ Эффективное продвижение во ВКонтакте.ру и Facebook
Ingria. Technopark St. Petersburg
 
Михеев Юрий - Применение современных инструментов интегрированного менеджмент...
Ingria. Technopark St. Petersburg
 
productronica 2013 Tageszeitung Tag 1 / daily newspaper day 1
Messe München GmbH
 
Ospmi Chapter Presentation
Dennis Bolles
 
17 Aralık 2014 Serap Mutlu Akbulut Konseri Resimleri
aokutur
 
Levi student consil
Durke1dd
 
BabbleLABEL [Web Ready 2010]
Ingria. Technopark St. Petersburg
 
Bio181 spring11
Danielle Carlock
 
Ingria games Joybits
Ingria. Technopark St. Petersburg
 
Citrex610 l-en-spa 3 citrex directo en alimentos(2)
CITREX
 
Inbound Marketing - Promotion
Liberty Digital Marketing
 
Механизмы государственной поддержки экспортно-ориентированных субъектов малог...
Ingria. Technopark St. Petersburg
 
Ad

Similar to How to define an api (20)

PPT
Api desgin
Prabhat gangwar
 
PDF
How to design good api
Osama Shakir
 
PDF
How To Design A Good A P I And Why It Matters G O O G L E
guestbe92f4
 
PDF
Keynoteof A P I
sounthar rajan
 
PDF
Api design
xandesimoes
 
PDF
API design
sakpece
 
PDF
ApiDesign
Harshdip Singh
 
PDF
How to Design a Good API and Why it Matters.pdf
SimranjyotSuri
 
PPT
How to design effective APIs
Bansilal Haudakari
 
PPTX
Golden Rules of API Design
David Koelle
 
PPTX
Developer Friendly API Design
theamiableapi
 
PDF
Api Design Patterns Meap V07 Meap V07 Jj Geewax
mohellrakes
 
ODP
Designing Good API & Its Importance
Imran M Yousuf
 
PPTX
Adobe Acrobat Reader Download Free - 2025.001.20432
robinaworknsolution
 
PPTX
Microsoft Office Professional Plus Greek 2025
beenachuhdri
 
PPTX
Nitro PDF Pro Enterprise Crack Download (Latest 2025)
choudhryrobii
 
PPTX
Adobe Acrobat Pro DC 2025.001.20432 Crack + Serial Key
alinaveedwns
 
PPTX
Microsoft Office 2021 free download of full version with crack
choudhryrobii
 
PPTX
Ratiborus KMS Tools Portable Download (Latest 2025) Crack
robinaworknsolution
 
PPTX
KMSAuto++ 1.9.9 Free Download 2025 Crack
naveedbeena68
 
Api desgin
Prabhat gangwar
 
How to design good api
Osama Shakir
 
How To Design A Good A P I And Why It Matters G O O G L E
guestbe92f4
 
Keynoteof A P I
sounthar rajan
 
Api design
xandesimoes
 
API design
sakpece
 
ApiDesign
Harshdip Singh
 
How to Design a Good API and Why it Matters.pdf
SimranjyotSuri
 
How to design effective APIs
Bansilal Haudakari
 
Golden Rules of API Design
David Koelle
 
Developer Friendly API Design
theamiableapi
 
Api Design Patterns Meap V07 Meap V07 Jj Geewax
mohellrakes
 
Designing Good API & Its Importance
Imran M Yousuf
 
Adobe Acrobat Reader Download Free - 2025.001.20432
robinaworknsolution
 
Microsoft Office Professional Plus Greek 2025
beenachuhdri
 
Nitro PDF Pro Enterprise Crack Download (Latest 2025)
choudhryrobii
 
Adobe Acrobat Pro DC 2025.001.20432 Crack + Serial Key
alinaveedwns
 
Microsoft Office 2021 free download of full version with crack
choudhryrobii
 
Ratiborus KMS Tools Portable Download (Latest 2025) Crack
robinaworknsolution
 
KMSAuto++ 1.9.9 Free Download 2025 Crack
naveedbeena68
 
Ad

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