Best Practice for Asp.net API
• Restful API != Good API.
• Do what makes Sense
• Do what consumers need
Most Important things to recall
Design API
Tips
• Keep it Simple( Simple != Easy)
• No need to be creative
• Use handful of http Code
• Return/Provide what is needed
• Structure APi to make finding error easy
• Nesting resources for hierarchical objects.
Be
consistent
with the ff:
• Plurality
• Use of Nouns and verbs
• Result size
• Sorting and filtering
• Paging
Implementation
• Accept and respond with JSON.
• Versioning--> API should
stand the test of time
• Use URL versioning
• Use SSL
• Pick and
Authentication strategy that is
not basic
• Use DTO
Implementation continued
• Controller should know "Where" not "how"
• Keep validating in back end side
• Separate validation logic from object
• Handle errors gracefully and return standard error
codes.
Controller Request Validator
Handler
Service
Documentation
• Use Documentation Tools
• Keep Updated
• Remove Properties on maintenance phase
• Make easy for everyone to read
• Test readability with other devs
Upon deprecation
• Give notice for deprecation
• Point out different version or
replacement to every method and
address that is deprecated
Performance
tips
Performance is also an
important consideration.
Avoid returning too much
data at once.
Use caching to avoid repeated
queries
Last
General
Tips
• have consistency by following web
standards and conventions
• Paths of endpoints should be consistent
• use nouns only since the HTTP methods
indicate the action we want to take.
• Paths of nested resources should come after
the path of the parent resource.
• Paths should tell what is returned or
manipulated without the need to read extra
documentation to understand what it’s
doing.

Api design tips

  • 1.
    Best Practice forAsp.net API • Restful API != Good API. • Do what makes Sense • Do what consumers need Most Important things to recall
  • 2.
    Design API Tips • Keepit Simple( Simple != Easy) • No need to be creative • Use handful of http Code • Return/Provide what is needed • Structure APi to make finding error easy • Nesting resources for hierarchical objects.
  • 3.
    Be consistent with the ff: •Plurality • Use of Nouns and verbs • Result size • Sorting and filtering • Paging
  • 4.
    Implementation • Accept andrespond with JSON. • Versioning--> API should stand the test of time • Use URL versioning • Use SSL • Pick and Authentication strategy that is not basic • Use DTO
  • 5.
    Implementation continued • Controllershould know "Where" not "how" • Keep validating in back end side • Separate validation logic from object • Handle errors gracefully and return standard error codes. Controller Request Validator Handler Service
  • 6.
    Documentation • Use DocumentationTools • Keep Updated • Remove Properties on maintenance phase • Make easy for everyone to read • Test readability with other devs
  • 7.
    Upon deprecation • Givenotice for deprecation • Point out different version or replacement to every method and address that is deprecated
  • 8.
    Performance tips Performance is alsoan important consideration. Avoid returning too much data at once. Use caching to avoid repeated queries
  • 9.
    Last General Tips • have consistencyby following web standards and conventions • Paths of endpoints should be consistent • use nouns only since the HTTP methods indicate the action we want to take. • Paths of nested resources should come after the path of the parent resource. • Paths should tell what is returned or manipulated without the need to read extra documentation to understand what it’s doing.