Piping the output of a Binary API Response

           · ·

Company Logo API

So I recently found this super cool service that returns a company logo from an open free API. You can alter the size, greyscale, and format all within a single request. This endpont is completely free, just gotta give them some attribution. Here the company explains it best…

While services like Gravatar make it straightforward to pull in a user’s default avatar, we haven’t found anything that caters well to company logos. And yet there’s a lot of clear use-cases ranging from setting an organization’s default image on signup to pulling in logos next to job listings.

API

The API is incredibly simple, taking a company’s domain and returning an image.

GET https://logo.clearbit.com/:domain

Behind the scenes we’re using Clearbit’s Company API, pulling images from lots of different sources such as Twitter, Facebook, Wikipedia, or the company’s own site’s meta links. We then resize and standardize the images, serving them up from a CDN.

Example

Here’s the API in action - an img tag containing the domain gohugo.io

<img src="https://logo.clearbit.com/gohugo.io">

What if you didn’t have a browser?

Implicitly doing a GET request for you here as the source of the img html tag…

So their example is great and all, but when I test APIs I tend to immediately use my favorite client – https://httpie.org/. Which so happens to be a CLI client. But wait this endpoint returns an image, which is a binary format, ie. my beloved httpie client is not working for this endpoint! Well fuck that! I knew there had to be a way… Since Preview.app is the default image viewer on macOS I thought I’d just pipe the result of this request to this program (to view my image)!

code example

So after a quick duckduckgo query, it resulted the httpie command goes like this…

http GET https://logo.clearbit.com/gohugo.io | open -f -a /Applications/Preview.app

So of course this would simply just be for testing purposes, most likely will use the example they provided and put the logo in img tag. #superclean

Final Thoughts

So ya, I wouldn’t have written this short on either the API or the piping the output to satisfy my HTTP client, if I didn’t think it was legit!

But legit isn’t enough to go into production! However, the best use case I can see with this API service is embedding company logo in your app (mobile or web)! Never having to bloat up your personal assets folder with logos, just hit this service and get the latest and greatest designed branding for a company!

Perhaps I’ll write a little wrapper helper around this in Ruby or Go!

comments powered by Disqus