Generating PHP library code from OpenAPI

I’m working with a bunch of OpenAPI specs now I am working for Nexmo and so far I’m loving working with API descriptions. OpenAPI is the next iteration of what used to be called “Swagger”, a machine-readable way to describe your API and from that description create docs, code libraries, tests, and all sorts. Today’s post is a quick writeup of how I generated some PHP code so that I can refer back to this next time I want to do it! Continue reading

Make a POST Request from PHP With Guzzle

I work extensively with APIs and a variety of serverside scripting languages, and best practice does change over time. Many of the most popular posts on this blog are 10 years old, because apparently I was interesting in 2008. Two in particular from around that time relate to making POST requests from PHP … and I’d do it completely differently today. So, in an attempt to overcome some of the past crimes of the Internet in general and PHP in particular: here’s how to make a POST request in PHP, today, in a PHP 7+ world (it probably works in PHP 5 too). Continue reading

Vim settings for working with YAML

Having managed to avoid YAML until quite recently, my vim installation wasn’t well set up at all for working with it. It needs more config settings than plugins, so I thought I’d write down what I found helpful. I’m using it quite a lot now I’m working with OAS (used to be Swagger) API definitions. Continue reading

Documentation First: A Recipe for API Success

I’ve shipped a handful of greenfield APIs in recent months for different clients, and in each case I’ve been building the documentation before the API. I hadn’t really recognised it as a pattern until someone else commented on it, but I do find this approach has worked well for my projects, so I thought I’d share my thoughts on this in a bit more detail. Continue reading

Use Ngrok for Testing APIs on Dev

Recently I was hastily building an API for a client and I wanted to run some tests against it. I’ve written before about using Runscope for API testing, but this was against a local dev platform (inside a VM, not directly on my laptop) rather than a public API. The same problem arises if you want to access a local site or API from elsewhere or from a mobile device. In all these scenarios, ngrok is your friend. Continue reading

Working with PHP and Beanstalkd

I have just introduced Beanstalkd into my current PHP project; it was super-easy so I thought I’d share some examples and my thoughts on how a job queue fits in with a PHP web application.

The Scenario

I have an API backend and a web frontend on this project (there may be apps later. It’s a startup, there could be anything later). Both front and back ends are PHP Slim Framework applications, and there’s a sort of JSON-RPC going on in between the two.

The job queue will handle a few things we don’t want to do in real time on the application, such as:

  • updating counts of things like comments; when a comment is made, a job gets created and we can return to the user. At some point the job will get processed updating the counts of how many comments are on that thing, how many comments the user made, adding to a news feed of activities … you get the idea. Continue reading

DimpleJs Bubble/Scatterplots and Joind.in Data

DimpleJs is a wrapper for d3, the javascript charting library, which makes beautiful charts but is way more complicated than I want to cope with, so I was looking for a helper toolkit. I’ve been using dimplejs lately and wanted to write down what I did while I can remember, but I didn’t think my clients would thank me for publishing their data! Instead, I made some graphs using Joind.in‘s data, just pulling what I needed over the API and producing something like this:



Continue reading