Web Summer Camp Croatia: Writing API clients with HTTPlug
1.9.2016Title: Writing API clients with HTTPlug
Links: slides, tutorial repository
Co-Presenter: Márk Sági-Kazár
This was a 3 hour tutorial with many exercises the participants could do.
PSR-7 defines common interfaces for HTTP requests and responses but the libraries that need to send HTTP requests need more than that. HTTPlug defines an interface for HTTP clients and provides adapters for existing clients like Guzzle, as well as a plugin system operating directly on PSR-7. This tool chain allows building API clients that do not depend on a specific HTTP client at all.
This workshop by the two of the main authors of HTTPlug will cover:
- Working with PSR-7 request and response
- Using HTTPlug and the MessageFactory
- Bootstrapping clients explicitly or with Puli
- Using the PHP-HTTP plugin system
- Strategies for writing an API client.
I was invited to do a workshop at Web Summer Camp in Rovinj (yes, last year it was called PHP Summer Camp – it got bigger this year). This year, I did a workshop on building HTTP clients in PHP. I did the workshop together with Márk Sági-Kazár, the lead author of HTTPlug, the HTTP client abstraction on top of PSR-7. We used PSR-7 and HTTPlug to build a client against an example API to manage TODO items. Then we showed how to do a Symfony integration for such a client, and how the HttplugBundle can be used to debug requests that are done in Symfony. The slides are online on slides.com – though note that this was a hands-on workshop, important parts of the workshop are not visible on these slides. The workshop was well received and I hope to teach it again in the future.
Web Summer Camp is unique in being a conference that only consists of 3 hour hands-on workshops and no only talks – aside from a lightning talks session. There are workshops in the morning and in the afternoon, so during the 3 days, you get to do 6 in depth-workshops. This year, there was the PHP track with 2 parallel workshops, and an eZ publish track as well as a UX / agile track. The Summer Camp is a community organized event with a great atmosphere, nice evening activities – and keeping the prices impressively low for what you get. The included boat trip on saturday is another unique and awesome thing. In short, you should strongly consider visiting the Summer Camp next year!