GET endpoints to return JSON data, and another endpoint to receive and log incoming webhook data. Continue reading Tag Archives: http
HTTPMock for Testing a Golang API Client
HTTP Toolbox
There’s a slide deck, some exercises and a sample repo on GitHub … let’s dive in! Continue reading
Test Web Requests with a Local RequestBin
docker-compose configuration. Continue reading Make a POST Request from PHP With Guzzle
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 HTTP Tools Roundup
Changing Content Type with Slim Framework
$response = $app->response();
$response->header("Content-Type", "text/javascript");
The $app variable is the Slim\Slim instance for your application, once you have that, you can just add on any headers you need to with this call to header(). It wasn’t obvious to me and there weren’t a lot of resources for this, so I thought I’d share!
Twitter Search API Using PHP and Guzzle
file_get_contents in the general direction of the right URL. Continue reading Setting Multiple Headers in a PHP Stream Context
In fact, you’ve been able to pass this as an array since PHP 5.2.10, so to set multiple headers in the stream context, I just used this:
<?php
$options = ["http" => [
"method" => "POST",
"header" => ["Authorization: token " . $access_token,
"Content-Type: application/json"],
"content" => $data
]];
$context = stream_context_create($options);
The $access_token had been set elsewhere (in fact I usually put credentials in a separate file and exclude it from source control in an effort not to spread my access credentials further than I mean to!), and $data is already encoded as JSON. For completeness, you can make the POST request like this:
<?php
// make the request
$response = file_get_contents($url, false, $context);
Hopefully this will help someone else doing the same thing next time (or at least I know I can come back here when I can’t remember!), the array approach seems more elegant and maintainable to me.
Pretty-Printing JSON with Python’s JSON Tool
curl http://api.joind.in | python -mjson.tool
You need python installed, but the JSON extension is probably included, and that’s all you need for this tool. The result is something like:
You can also use this approach to present JSON data that has been captured to another file, for example, it’s a handy trick that I use often when developing something with JSON as a data format.


