$30 off During Our Annual Pro Sale. View Details »

API's and You

API's and You

I recently decided to share the knowledge I have gained over the past year while trying to build an API for the startup I work for.

If you're interested in seeing the next part of the talk, and happen to live in Austin, Texas you should come to the next Laravel Meetup on July 8th. Link here: http://www.meetup.com/Laravel-Austin/

Links within the presentation:
* http://twitter.com/HSkrasek
* https://github.com/fzaninotto/Faker
* http://info.apigee.com/Portals/62317/docs/web%20api.pdf
* https://leanpub.com/build-apis-you-wont-hate

Hunter Skrasek

June 10, 2014
Tweet

More Decks by Hunter Skrasek

Other Decks in Programming

Transcript

  1. APIs and You
    Hunter Skrasek - @HSkrasek

    View Slide

  2. Who's this guy?

    View Slide

  3. Born and Raised
    Dallas/Fort Worth area

    View Slide

  4. Came for school, stayed for work
    Austin is pretty cool though!

    View Slide

  5. So.. Whats an API?

    View Slide

  6. • API aka Application Programming Interface
    • Set of HTTP Requests in the "Web" world
    • Made with XML (yuck), or JSON (yay)
    • Synonymous with a Web Service
    • Remember SOAP and SOA? No? Good
    • Moving towards REST


    View Slide

  7. REST
    • Less RESTafarian, more "pragmatic REST"
    • Think from the "outside in"

    View Slide

  8. Let's get started!

    View Slide

  9. Database Seeding
    Yay

    View Slide

  10. • Let's assume you've already made the database
    • Or we will be here forever
    • Dummy data for acceptance tests
    • DO NOT JUST COPY PRODUCTION DATA!!!!

    View Slide

  11. But how do I make these?
    • Use Faker!
    • Better at BS than college students
    • https://github.com/fzaninotto/Faker
    • Break it down into logical groups
    • Doesn't have to be 1 to 1

    View Slide

  12. Seeder Example

    View Slide

  13. Endpoint Planning
    • What does your API need?
    • Talk to the customers! (Or business)
    • List all the "Actions" or possible endpoints

    View Slide

  14. Users Posts Projects
    Create
    Read
    Update
    Delete
    List
    Image
    Posts
    Projects
    Create
    Read
    Update
    Delete
    List (category, author)
    Comments
    Create
    Read
    Update
    Delete
    List
    (category, author)
    Comments

    View Slide

  15. Endpoint Theory
    • GET Resources
    • GET /resources - List all resources
    • GET /resources/X - Get resource X
    • GET /resources/X,Y,Z - Get resources X, Y, X
    • GET /resources/X/subresources/Y - Get sub
    resource Y of resource X

    View Slide

  16. Speaking of SubResources
    • SubResources vs. Embedded
    • Either is fine, both is better
    • We will stick with subresources for now

    View Slide

  17. –Somebody Somewhere
    “Auto Increment ID is bad.”

    View Slide

  18. Endpoint Theory
    • DELETE Resources
    • DELETE /resources - Delete all the things! (Not
    really)
    • DELETE /resources/X - Delete resource X
    • DELETE /resources/X,Y,Z - Delete resources X, Y, X
    • DELETE /resources/X/subresources/Y - Get sub
    resource Y of resource X

    View Slide

  19. POST vs. PUT
    • Long story short.. who cares!
    • Make sure it is consistent.
    • “Generally speaking, PUT is used if you know the
    entire URL before hand and the action is idempotent.
    Idempotent is a fancy word for ‘can do it over and over
    again without causing different results’.”

    View Slide

  20. Endpoint Theory
    • Plural vs. Singular
    • Consistency is key
    • No /users and /user/1
    • Example: opportunity becomes opportunities

    View Slide

  21. Questions?

    View Slide

  22. Sources
    • Apigee’s Web API Design

    View Slide

  23. Sources
    • Phil Sturgeons Build API’s
    You Wont Hate

    View Slide