Getting the share count of a URL
– Edit
At work I’m working on a project in which we need to track the share count of an URL. Below are my quick notes.https://www.bram.us/2016/01/11/getting-the-share-count-of-a-url/
Posts tagged with api
– Edit
At work I’m working on a project in which we need to track the share count of an URL. Below are my quick notes.https://www.bram.us/2016/01/11/getting-the-share-count-of-a-url/
– Edit
Every year the city of Antwerp (my hometown :-)) organises lots of activities, such as an Ice rink, a Christmas market, a Santa Run and of course fireworks in the month of december. To inform people of which activities are happening where and when my team and I created a mobile app commissioned by the city council. The app is called "Winter in A" and is available on both Android's Play Store and iOS' App Store.
The administrators of the app can enter content in a custom installation of Blender, our Laravel based application. Blender will write of a bunch of json-files that are read by the mobile apps. Here's the file for all the events (english localization): https://api.winterapp.be/en/events.json. We use our homegrown laravel-fractal package to easily transform database records to json. Here's the export handler that's in charge of the exporting of events:
namespace App\Services\Export\ExportHandlers;
use App\Repositories\EventRepository;
use App\Services\Export\ExportHandler;
use App\Services\Export\Transformers\EventTransformer;
class Events implements ExportHandler
{
/**
* @var \App\Repositories\EventRepository
*/
protected $eventRepository;
public function __construct(EventRepository $eventRepository)
{
$this->eventRepository = $eventRepository;
}
/**
* Get the json for the given locale.
*
* @param string $locale
*
* @return mixed
*/
public function getJsonForLocale($locale)
{
return fractal()
->collection($this->eventRepository->getAllOnline())
->transformWith(new EventTransformer($locale))
->toJson();
}
}
The EventTransformer itself:
namespace App\Services\Export\Transformers;
use App\Models\Event;
use App\Services\Export\Format;
use App\Services\ValueObjects\Period;
use League\Fractal\TransformerAbstract;
use Spatie\MediaLibrary\Media;
class EventTransformer extends TransformerAbstract
{
/**
* @var
*/
protected $locale;
public function __construct($locale)
{
$this->locale = $locale;
}
public function transform(Event $event)
{
return [
'id' => $event->id,
'name' => $event->translate($this->locale)->name,
'text' => htmlToMarkdown($event->translate($this->locale)->text),
...
'images' => $event->getMedia('images')->map(function (Media $media) {
return [
'thumb' => $media->getUrl('thumb'),
'full' => $media->getUrl('full')
];
}),
];
}
}
To handle peaks in usage of the app we use CloudFlare. In this article they explain what they do. Cloudflare has this awesome feature called "Always online", to make sure the API is online even if our server is not.
The first events of Winter in Antwerp are starting tomorrow. The last ones are scheduled in the first days of 2016. I'll share some more tidbits of the code then.
Join 9,500+ smart developers
Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.
No spam. Unsubscribe anytime. You can also follow me on X.
"As a Laravel developer, this is the one newsletter I most look forward to. Freek has a talent for distilling packages or techniques down to something immediately useful - one tip can save you hours and even weeks. It's concise and practical and highly relevant."
by Freek Van der Herten – 1 minute read – Edit
Today I released a new package called laravel-fractal. It provides a Fractal service provider for Laravel. If you don't know what Fractal does, take a peek at their intro. Shortly said, Fractal is very useful to transform data before using it in an API. Using Fractal data can be transformed like…
– Edit
When we built Facebook's mobile applications, we needed a data-fetching API powerful enough to describe all of Facebook, yet simple enough to be easy to learn and use by our product developers. We developed GraphQL three years ago to fill this need. Today it powers hundreds of billions of API calls a day. This year we've begun the process of open-sourcing GraphQL by drafting a specification, releasing a reference implementation, and forming a community around it at graphql.org.https://code.facebook.com/posts/1691455094417024/graphql-a-data-query-language/
There's already a package to use GraphQL with Laravel.
– Edit
V2.0 of the API was a weird hybrid of RESTful and RPC practices, which required everyone to learn our own special style of API design. With a few minor exceptions, API v3.0 is fully RESTful. This allows us to express in a couple dozen resources what it took the last version 120 distinct endpoints to accomplish.http://devs.mailchimp.com/blog/api-v3-0-officially-launched/
Consuming this API doesn't seem to be that hard but I hope they'll release a PHP wrapper soon.
– Edit
... it’s important to remember that API design isn’t strictly about the practical implications on client and server software. The audience for an API is the developer who is going to consume it. Per the "principle of least astonishment," developers will have an easier time learning and understanding an API if it follows the same conventions as other APIs they’re familiar with.https://blogs.dropbox.com/developers/2015/04/how-many-http-status-codes-should-your-api-use/
– Edit
Having documentation on your API is highly beneficial. If it is well written you're likely going to receive less questions by consumers of your API about how it works.
Aglio is a nice tool that I've been using to generate API documentation. In goes the Markdown, out comes the beautiful documentation.
– Edit
Google introduced a new method that verifies you are human without you having to solve a riddle.
On websites using this new API, a significant number of users will be able to securely and easily verify they’re human without actually having to solve a CAPTCHA. Instead, with just a single click, they’ll confirm they are not a robot.
It looks like this:

http://googleonlinesecurity.blogspot.nl/2014/12/are-you-robot-introducing-no-captcha.html