Follow these steps to create APIs.
- Clone the starter from GitHub repository using this command into your machine’s local servergit clone https://github.com/vishalanandl177/php-slim-starter.git
- Edit the file src/config/config.php, set the server to development by setting the PHP constantcomment the produnction serverdefine(“SERVER”, “DEVELOPMENT”);and set the timezone, default is UTC//define(“SERVER”, “PRODUCTION”);define(“TIMEZONE”, “UTC”);
- Configure the database connection. Edit the file src/config/connect.php
if(SERVER ==’DEVELOPMENT’){
define(“HOST”, “localhost”); // set the local host name for local machine
define(“USER”, “”); // set the database username for local machine
define(“PASSWORD”, “”); // set the database password for local machine
define(“DATABASE”, “”); // set the database name for local machine
define(“BASE_URL_STRING”, getBaseUrl());
}if(SERVER ==’PRODUCTION’){
define(“HOST”, “localhost”); // set the production host name
define(“USER”, “”); // set the production side database username
define(“PASSWORD”, “”); // set the production side database password
define(“DATABASE”, “”); // set the production side database name
define(“BASE_URL_STRING”, getBaseUrl());
}
This starter has two APIs integrated. One for GET method and other is for POST method. In index.php file, in root directory, you can see the two APIs
$Rest->get(‘/get-call’, array($DeviceCtr, ‘getCall’));
$Rest->post(‘/post-call’, array($DeviceCtr, ‘postCall’));
0 Comments