aalfiann/slim-api-skeleton

This is a skeleton to built rest api with slim framework 3.

1.1.0 2019-05-13 21:12 UTC

This package is auto-updated.

Last update: 2024-10-14 10:23:00 UTC


README

Version Downloads License

This is a skeleton to built rest api with slim framework 3.

Dependencies

  • Logger >> monolog/monolog
  • HTTP Cache >> slim/http-cache
  • ETag Middleware >> aalfiann/slim-etag-middleware

Installation

Install this package via Composer.

composer create-project aalfiann/slim-api-skeleton [my-app-name]

Getting Started

How to create new application

  • Go to modules directory
  • Create new folder my-app
  • To create routes, you should follow this pattern >> *.router.php
  • Done

Example

This is the my-app.router.php file

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

// Route for /my-app
$app->group('/my-app', function($app) {

    // Show index page
    // Try to open browser to http://yourdomain.com/my-app/
    $app->get('/', function (Request $request, Response $response) {
        $data = [
            'welcome' => 'Hello World, this is my-app index page.',
            'message' => 'This is my first app rest api with slim-api-skeleton.'
        ];
        return $response->withJson($data,200,JSON_PRETTY_PRINT);
    })->setName("/");

});

Note: