際際滷

際際滷Share 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)

Scaling API Design - Nordic APIs 2014
Scaling API Design - Nordic APIs 2014Scaling API Design - Nordic APIs 2014
Scaling API Design - Nordic APIs 2014
Jason Harmon
Scaling API Design
Scaling API DesignScaling API Design
Scaling API Design
Jason Harmon
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessible
Victor Trakhtenberg
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...
apidays
Scaling API Design
Scaling API DesignScaling API Design
Scaling API Design
Jason Harmon
Rest in practice
Rest in practiceRest in practice
Rest in practice
Ian Brennan
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,...
apidays
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.
Diogo Lucas
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)
Open API Initiative (OAI)
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
apidays
What is Swagger?
What is Swagger?What is Swagger?
What is Swagger?
Philip Senger
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
Jason Harmon
Pain Points In API Development? Theyre Everywhere
Pain Points In API Development? Theyre EverywherePain Points In API Development? Theyre Everywhere
Pain Points In API Development? Theyre Everywhere
Nordic APIs
Past, Present, Future of APIS
Past, Present, Future of APISPast, Present, Future of APIS
Past, Present, Future of APIS
Jason Harmon
Mulesoft Raml APIs
Mulesoft Raml APIsMulesoft Raml APIs
Mulesoft Raml APIs
akshay yeluru
Moving into API documentation writing
Moving into API documentation writingMoving into API documentation writing
Moving into API documentation writing
Ellis Pratt
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...
SmartBear
Scaling API Design - Nordic APIs 2014
Scaling API Design - Nordic APIs 2014Scaling API Design - Nordic APIs 2014
Scaling API Design - Nordic APIs 2014
Jason Harmon
Scaling API Design
Scaling API DesignScaling API Design
Scaling API Design
Jason Harmon
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessible
Victor Trakhtenberg
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...
apidays
Scaling API Design
Scaling API DesignScaling API Design
Scaling API Design
Jason Harmon
Rest in practice
Rest in practiceRest in practice
Rest in practice
Ian Brennan
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,...
apidays
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.
Diogo Lucas
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)
Open API Initiative (OAI)
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
apidays
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
Jason Harmon
Pain Points In API Development? Theyre Everywhere
Pain Points In API Development? Theyre EverywherePain Points In API Development? Theyre Everywhere
Pain Points In API Development? Theyre Everywhere
Nordic APIs
Past, Present, Future of APIS
Past, Present, Future of APISPast, Present, Future of APIS
Past, Present, Future of APIS
Jason Harmon
Mulesoft Raml APIs
Mulesoft Raml APIsMulesoft Raml APIs
Mulesoft Raml APIs
akshay yeluru
Moving into API documentation writing
Moving into API documentation writingMoving into API documentation writing
Moving into API documentation writing
Ellis Pratt
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...
SmartBear

Viewers also liked (20)

The Groovy Way
The Groovy WayThe Groovy Way
The Groovy Way
Gabriel Dogaru
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
Dun & Bradstreet Cloud Innovation Center
Non functional requirements framework
Non functional requirements frameworkNon functional requirements framework
Non functional requirements framework
wweinmeyer79
Performance Testing REST APIs
Performance Testing REST APIsPerformance Testing REST APIs
Performance Testing REST APIs
Jason Weden
Yow Conference Dec 2013 Netflix Workshop 際際滷s with Notes
Yow Conference Dec 2013 Netflix Workshop 際際滷s with NotesYow Conference Dec 2013 Netflix Workshop 際際滷s with Notes
Yow Conference Dec 2013 Netflix Workshop 際際滷s with Notes
Adrian Cockcroft
Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016
Adrian Cockcroft
Monitorama 2015 Netflix Instance Analysis
Monitorama 2015 Netflix Instance AnalysisMonitorama 2015 Netflix Instance Analysis
Monitorama 2015 Netflix Instance Analysis
Brendan Gregg
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...
John Musser
舒仄亳 丱舒仍亳仍仂于_ 亅亠从亳于仆仂亠 仗仂亟于亳亢亠仆亳亠 于仂 仂仆舒从亠. 亳 Facebook
舒仄亳 丱舒仍亳仍仂于_ 亅亠从亳于仆仂亠 仗仂亟于亳亢亠仆亳亠 于仂 仂仆舒从亠. 亳 Facebook舒仄亳 丱舒仍亳仍仂于_ 亅亠从亳于仆仂亠 仗仂亟于亳亢亠仆亳亠 于仂 仂仆舒从亠. 亳 Facebook
舒仄亳 丱舒仍亳仍仂于_ 亅亠从亳于仆仂亠 仗仂亟于亳亢亠仆亳亠 于仂 仂仆舒从亠. 亳 Facebook
Ingria. Technopark St. Petersburg
亳亠亠于 豫亳亶 - 亳仄亠仆亠仆亳亠 仂于亠仄亠仆仆 亳仆仄亠仆仂于 亳仆亠亞亳仂于舒仆仆仂亞仂 仄亠仆亠亟亢仄亠仆...
亳亠亠于 豫亳亶 - 亳仄亠仆亠仆亳亠 仂于亠仄亠仆仆 亳仆仄亠仆仂于 亳仆亠亞亳仂于舒仆仆仂亞仂 仄亠仆亠亟亢仄亠仆...亳亠亠于 豫亳亶 - 亳仄亠仆亠仆亳亠 仂于亠仄亠仆仆 亳仆仄亠仆仂于 亳仆亠亞亳仂于舒仆仆仂亞仂 仄亠仆亠亟亢仄亠仆...
亳亠亠于 豫亳亶 - 亳仄亠仆亠仆亳亠 仂于亠仄亠仆仆 亳仆仄亠仆仂于 亳仆亠亞亳仂于舒仆仆仂亞仂 仄亠仆亠亟亢仄亠仆...
Ingria. Technopark St. Petersburg
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
Ospmi Chapter Presentation
Ospmi Chapter PresentationOspmi Chapter Presentation
Ospmi Chapter Presentation
Dennis Bolles
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
BabbleLABEL [Web Ready 2010]
BabbleLABEL [Web Ready 2010]BabbleLABEL [Web Ready 2010]
BabbleLABEL [Web Ready 2010]
Ingria. Technopark St. Petersburg
Bio181 spring11
Bio181 spring11Bio181 spring11
Bio181 spring11
Danielle Carlock
Ingria games Joybits
Ingria games JoybitsIngria games Joybits
Ingria games Joybits
Ingria. Technopark St. Petersburg
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
Inbound Marketing - Promotion
Inbound Marketing - PromotionInbound Marketing - Promotion
Inbound Marketing - Promotion
Liberty Digital Marketing
亠舒仆亳亰仄 亞仂亟舒于亠仆仆仂亶 仗仂亟亟亠亢从亳 从仗仂仆仂-仂亳亠仆亳仂于舒仆仆 弍亠从仂于 仄舒仍仂亞...
亠舒仆亳亰仄 亞仂亟舒于亠仆仆仂亶 仗仂亟亟亠亢从亳 从仗仂仆仂-仂亳亠仆亳仂于舒仆仆 弍亠从仂于 仄舒仍仂亞...亠舒仆亳亰仄 亞仂亟舒于亠仆仆仂亶 仗仂亟亟亠亢从亳 从仗仂仆仂-仂亳亠仆亳仂于舒仆仆 弍亠从仂于 仄舒仍仂亞...
亠舒仆亳亰仄 亞仂亟舒于亠仆仆仂亶 仗仂亟亟亠亢从亳 从仗仂仆仂-仂亳亠仆亳仂于舒仆仆 弍亠从仂于 仄舒仍仂亞...
Ingria. Technopark St. Petersburg
Non functional requirements framework
Non functional requirements frameworkNon functional requirements framework
Non functional requirements framework
wweinmeyer79
Performance Testing REST APIs
Performance Testing REST APIsPerformance Testing REST APIs
Performance Testing REST APIs
Jason Weden
Yow Conference Dec 2013 Netflix Workshop 際際滷s with Notes
Yow Conference Dec 2013 Netflix Workshop 際際滷s with NotesYow Conference Dec 2013 Netflix Workshop 際際滷s with Notes
Yow Conference Dec 2013 Netflix Workshop 際際滷s with Notes
Adrian Cockcroft
Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016
Adrian Cockcroft
Monitorama 2015 Netflix Instance Analysis
Monitorama 2015 Netflix Instance AnalysisMonitorama 2015 Netflix Instance Analysis
Monitorama 2015 Netflix Instance Analysis
Brendan Gregg
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...
John Musser
舒仄亳 丱舒仍亳仍仂于_ 亅亠从亳于仆仂亠 仗仂亟于亳亢亠仆亳亠 于仂 仂仆舒从亠. 亳 Facebook
舒仄亳 丱舒仍亳仍仂于_ 亅亠从亳于仆仂亠 仗仂亟于亳亢亠仆亳亠 于仂 仂仆舒从亠. 亳 Facebook舒仄亳 丱舒仍亳仍仂于_ 亅亠从亳于仆仂亠 仗仂亟于亳亢亠仆亳亠 于仂 仂仆舒从亠. 亳 Facebook
舒仄亳 丱舒仍亳仍仂于_ 亅亠从亳于仆仂亠 仗仂亟于亳亢亠仆亳亠 于仂 仂仆舒从亠. 亳 Facebook
Ingria. Technopark St. Petersburg
亳亠亠于 豫亳亶 - 亳仄亠仆亠仆亳亠 仂于亠仄亠仆仆 亳仆仄亠仆仂于 亳仆亠亞亳仂于舒仆仆仂亞仂 仄亠仆亠亟亢仄亠仆...
亳亠亠于 豫亳亶 - 亳仄亠仆亠仆亳亠 仂于亠仄亠仆仆 亳仆仄亠仆仂于 亳仆亠亞亳仂于舒仆仆仂亞仂 仄亠仆亠亟亢仄亠仆...亳亠亠于 豫亳亶 - 亳仄亠仆亠仆亳亠 仂于亠仄亠仆仆 亳仆仄亠仆仂于 亳仆亠亞亳仂于舒仆仆仂亞仂 仄亠仆亠亟亢仄亠仆...
亳亠亠于 豫亳亶 - 亳仄亠仆亠仆亳亠 仂于亠仄亠仆仆 亳仆仄亠仆仂于 亳仆亠亞亳仂于舒仆仆仂亞仂 仄亠仆亠亟亢仄亠仆...
Ingria. Technopark St. Petersburg
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
Ospmi Chapter Presentation
Ospmi Chapter PresentationOspmi Chapter Presentation
Ospmi Chapter Presentation
Dennis Bolles
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
亠舒仆亳亰仄 亞仂亟舒于亠仆仆仂亶 仗仂亟亟亠亢从亳 从仗仂仆仂-仂亳亠仆亳仂于舒仆仆 弍亠从仂于 仄舒仍仂亞...
亠舒仆亳亰仄 亞仂亟舒于亠仆仆仂亶 仗仂亟亟亠亢从亳 从仗仂仆仂-仂亳亠仆亳仂于舒仆仆 弍亠从仂于 仄舒仍仂亞...亠舒仆亳亰仄 亞仂亟舒于亠仆仆仂亶 仗仂亟亟亠亢从亳 从仗仂仆仂-仂亳亠仆亳仂于舒仆仆 弍亠从仂于 仄舒仍仂亞...
亠舒仆亳亰仄 亞仂亟舒于亠仆仆仂亶 仗仂亟亟亠亢从亳 从仗仂仆仂-仂亳亠仆亳仂于舒仆仆 弍亠从仂于 仄舒仍仂亞...
Ingria. Technopark St. Petersburg

Similar to 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
Joy George
How to design good api
How to design good apiHow to design good api
How to design good api
Osama Shakir
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
apidays
Angular 2
Angular 2Angular 2
Angular 2
Travis van der Font
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
Peter Hendriks
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
rsebbe
Building a REST API for Longevity
Building a REST API for LongevityBuilding a REST API for Longevity
Building a REST API for Longevity
MuleSoft
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
Patrick Savalle
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)
Tom Johnson
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...
apidays
Keynoteof A P I
Keynoteof A P IKeynoteof A P I
Keynoteof A P I
sounthar rajan
Revamping Mailjet API documentation @ ParisAPI meetup
Revamping Mailjet API documentation @ ParisAPI meetupRevamping Mailjet API documentation @ ParisAPI meetup
Revamping Mailjet API documentation @ ParisAPI meetup
Mailjet
How to design effective APIs
How to design effective APIsHow to design effective APIs
How to design effective APIs
Bansilal Haudakari
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
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)
Peter Hendriks
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
GOG.com dev team
How aspects clean your code
How aspects clean your codeHow aspects clean your code
How aspects clean your code
Barbara Fusinska
API presentation
API presentationAPI presentation
API presentation
Carlos Justiniano
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
Damian Harvey
API Design - developing for developers
API Design - developing for developersAPI Design - developing for developers
API Design - developing for developers
Joy George
How to design good api
How to design good apiHow to design good api
How to design good api
Osama Shakir
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
apidays
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
Peter Hendriks
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
rsebbe
Building a REST API for Longevity
Building a REST API for LongevityBuilding a REST API for Longevity
Building a REST API for Longevity
MuleSoft
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
Patrick Savalle
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)
Tom Johnson
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...
apidays
Revamping Mailjet API documentation @ ParisAPI meetup
Revamping Mailjet API documentation @ ParisAPI meetupRevamping Mailjet API documentation @ ParisAPI meetup
Revamping Mailjet API documentation @ ParisAPI meetup
Mailjet
How to design effective APIs
How to design effective APIsHow to design effective APIs
How to design effective APIs
Bansilal Haudakari
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
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)
Peter Hendriks
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
GOG.com dev team
How aspects clean your code
How aspects clean your codeHow aspects clean your code
How aspects clean your code
Barbara Fusinska
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
Damian Harvey

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