Creating a secure API server
In this recipe, we'll create a simple API to display some information from our database. To control who has access to the data, we allow users to create keys and use that key in their API request.
Getting ready
For this recipe, we need a standard installation of Laravel and a configured MySQL database.
How to do it...
To complete this recipe, we'll follow these given steps:
In our database, create a table to hold the API keys as given in the following code:
CREATE TABLE api ( id int(10) unsigned NOT NULL AUTO_INCREMENT, name varchar(255) DEFAULT NULL, api_key varchar(255) DEFAULT NULL, status tinyint(1) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
In the database, create a table for some example data to access as shown in the following code:
CREATE TABLE shows (id int(10) unsigned NOT NULL AUTO_INCREMENT,name varchar(200) NOT NULL,year int(11) NOT NULL,created_at datetime NOT NULL,updated_at datetime NOT NULL,PRIMARY KEY (id)) ENGINE=InnoDB...