Openlicenses API

A Lumen based API to quickly download and save Open Souce Licences

: php

Concepts Used

  • REST API
  • NoSQL
  • Web Framework

Features

  • 3 Modes
  • Website and API

Code Link


Introduction

While working on personal projects, I often need to include a LICENSE file which is usually Open Source.

But to do that, I have to search the net, download the file and save . All of this takes too much time and needs me to move away from the keyboard and the Terminal.

Hence I thought of making an API so that I can use tools like wget to save the licenses quickly on the Terminal.

Working

I have used Lumen PHP micro-framework to define the routes and set the API endpoints.

I really like working with Lumen because it is very fast and lightweight. It is made specially for making APIs for REST based web services.

Now to get the Licenses, I used a PHP library called Simple HTML DOM Parser to scrape the Licences from a reliable source.

The Licenses are scraped from choosealicense.org and served as either plain text or HTML.

The whole project is hosted on Heroku.

Features

The API Documentation provides ids for various Licences which can be accessed as follows:

GET https://openlicensesapi.herokuapp.com/{id}

Also you can choose to get a HTML or plaintext(default) output.

GET https://openlicensesapi.herokuapp.com/{id}/text

OR

GET https://openlicensesapi.herokuapp.com/{id}/html

Thus , for example to download the GNU GPL License, navigate to the project directly and type this in the terminal :

wget openlicensesapi.herokuapp.com/2 -O LICENSE

Conclusion

It was a good experience hosting on heroku, this was the first time.

I use this API in the inipy project too.