O'Reilly logo

Laravel Application Development Cookbook by Terry Matula

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

  1. 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;
  2. In the database, create a table for some example data ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required