GETendpoints to return JSON data, and another endpoint to receive and log incoming webhook data. Continue reading
There's a slide deck, some exercises and a sample repo on GitHub ... let's dive in! Continue reading
docker-composeconfiguration. Continue reading
POSTrequests 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
$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!
file_get_contentsin the general direction of the right URL. Continue reading
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);
$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:
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.