2017 © Pedro Peláez
 

project slim3-api-skeleton

Slim 3 API Skeleton with content negotiation and performance in mind.

image

rrpadilla/slim3-api-skeleton

Slim 3 API Skeleton with content negotiation and performance in mind.

  • Wednesday, March 21, 2018
  • by rrpadilla
  • Repository
  • 3 Watchers
  • 11 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Slim 3 API Skeleton

This is an API skeleton using Slim 3 with content negotiation, authentication, error handling, cache and performance in mind. Error and exception handling is already configured for you. Check config/dependencies.php file., (*1)

Content Negotiation

Content Negotiation is handled using a query parameter and the HTTP Header "Accept". - The default query parameter is "output" and possible values are ("json" or "xml"). - If "output" parameter is not provided the HTTP Header "Accept" is used to determine which "Content type". If is not containing "application/json" or "application/xml" the default output will be "json"., (*2)

This project use the following packages/components: - Monolog for logging. - Slim-HttpCache. Read more - Noodlehaus's Config to load env.php file. - PHPUnit for testing., (*3)

You can integrate any third-party components found on Packagist: - Slim-Csrf. Read more - Slim-Flash. Read more, (*4)

Run it:

  1. $ cd my-app
  2. $ php -S 0.0.0.0:8888 -t public public/index.php
  3. Browse to http://localhost:8888

Key directories

  • app/: directory contains the core code of your application. All class files within the App namespace.
  • app/Controllers/: directory contains controllers and actions classes.
  • app/Handlers/: directory contains handlers classes (Error, PhpError, NotFound, NotAllowed).
  • app/Helpers/: directory contains helpers classes.
  • app/Middleware/: directory contains middleware classes.
  • app/Renders/: directory contains renders classes for specific responses (json and xml).
  • bootstrap/: directory contains files that bootstrap the framework and configure autoloading.
  • cache/: directory contains framework generated files for performance optimization such as the route file. Should be writable by your web server.
  • cache/routes/: directory is used to store routes generated files. For better performance on production. Should be writable by your web server.
  • config/: directory contains all of your application's configuration files (settings, dependencies, middleware).
  • logs/: directory contains your application's log files. Should be writable by your web server.
  • public/: directory contains the index.php file, which is the entry point for all requests entering your application.
  • routes/: directory contains all of the route definitions for your application. By default, 1 route file is included: routes.php.
  • tests/: directory contains your automated tests. An example PHPUnit is provided out of the box. To run tests: phpunit -- verbose tests/DefaultRoutesTest.php.
  • vendor/: directory contains your Composer dependencies.

Key files

  • public/index.php: entry point to application.
  • bootstrap/app.php: bootstrap the framework, configure auto-loading, dependencies, routes, etc.
  • env.php.dist: environment settings. Must copy it to env.php and modify that one.
  • config/dependencies.php: services for Pimple. Including (Database, Exception/Error handlers, Logger, etc).
  • config/middleware.php: application middleware.
  • config/settings.php: slim and others configurations. Rewrite Slim default settings (displayErrorDetails, routerCacheFile).
  • routes/routes.php: all application routes are here.
  • app/Controllers/ExampleAction.php: example Action class.
  • app/Helpers/ArrayToXml.php: Helper class to convert array to xml. Used by XmlApiView class.
  • app/Renders/ApiView.php: Render output based on a PSR-7 Request's Accept header.
  • app/Renders/JsonApiView.php: view wrapper for json responses (with error code). Return "meta" and "data". "meta" contains "error" (true/false) and "status" (HTTP Status code).
  • app/Renders/XmlApiView.php: view wrapper for xml responses (with error code). Return "meta" and "data". "meta" contains "error" (true/false) and "status" (HTTP Status code).

The Versions

21/03 2018

dev-master

9999999-dev https://github.com/rrpadilla/slim3-api-skeleton

Slim 3 API Skeleton with content negotiation and performance in mind.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rodolfo Ruiz

api skeleton slim-framework