How to Create REST API with PHP in 5 Minutes

apiplug_php_laravelIn this tutorial we are going to explain how to create a RESTful API with PHP Laravel framework which is connected to a MySQL or MongoDB in 5 minutes. After this tutorial you will be able to generate and download full source code of your own API also if you like you could deploy to your cloud server with a few clicks too.

You don’t have to write single line of code for this tutorial, you will be auto-generating and downloading all necessary backend source code with API Plug‘s web interface.

  1. The first step is about your datasource. To host your own API you will need a MySQL or MongoDB instance. You could also host your own Mysql or MongoDB instance in a cloud VPS such as DigitalOcean, AWS, etc. or choose a (DBaaS) Cloud Database as a Service provider such mLab, Compose, ObjectRocket, Google Cloud SQL etc. We are skipping this step and assume that you have chosen an option from above and now you have set your MySQL or MongoDB instance and created your tables or collections.
  2. Now it is time to generate your API from your datasource with API Plug. First login into your API Plug account and if you haven’t created yet, start a new API Project. Then click to “Link your DB” button and enter your datasource connection credentials.
    API Plug DB Connection
  3. If everything goes well you will see your endpoints list that auto-generated from your database tables or collections. If you don’t want to customise endpoint you could continue to next generation step.
  4. There are couple of options for generating your REST API. You could choose any language & framework from this list. To create a PHP API you need to select one of the PHP/Laravel option and click on to Generate your API button. We have different Laravel versions available right now and planning to add more PHP frameworks such as CodeIgniter, Slim Framework etc.
  5. Voila! It’s done ! Now you could select your auto generated PHP source code to continue selecting your deployment environment.
  6. Now you could download full your PHP REST API source code and test on your localhost and deploy to your cloud server or you could use our auto-deployment methods to deploy to your favourite cloud server providers such as DigitalOcean, Amazon, Heroku etc with a few clicks. You can use sandbox environment as hosted API during your development period. Click here to read more about API Plug Sandbox Environment.
  7. Also your automatically created Swagger API documentation will be ready on your panel. You could directly test your endpoints from your Swagger Documentation.

It is done. As you see creating a PHP Laravel REST-API from scratch is really easy and fast with API Plug.

Now it’s your turn, click here to start using API Plug to create your NodeJS API in minutes.

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *