Download the PHP package hoaaah/yii2-rest-api-template without Composer

On this page you can find all versions of the php package hoaaah/yii2-rest-api-template. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-rest-api-template

Yii 2 REST API Template


Yii2 REST API Template

This is a a REST API TEMPLATE with Yii2. This template use Yii2-Micro approach so it will be lightweight and easy to deploy.

Installation

The preferred way to install this template is through composer.

Either run

Setup your database configuration from config/db.php. Create your database because this template will not create it for you :)

Then run migration to create table in selected database.

Directory Structure

Since this template use MicroFramework approach, directory structure might be a little bit different from Yii2.

  config/             contains application configurations
  controllers/        contains Web controller classes
  migration/          contains list of your migration files
  models/             contains model classes
  modules/            contains your rest-api versioning (based on modules)
  vendor/             contains dependent 3rd-party packages
  web/                contains the entry script and Web resources

This template use modules as versioning pattern. Every version of API saved in a module. This template already have v1 module, so it means if consumer want to use v1 API, it can access https://your-api-url/v1/endpoint.

API Scenario

Supported Authentication

This template support 3 most used authentication. (Actually it's not me who make it, Yii2 already support it all :D ).

  1. HTTP Basic Auth: the access token is sent as the username. This should only be used when an access token can be safely stored on the API consumer side. For example, the API consumer is a program running on a server.
  2. Query parameter: the access token is sent as a query parameter in the API URL, e.g., https://example.com/users?access-token=xxxxxxxx. Because most Web servers will keep query parameters in server logs, this approach should be mainly used to serve JSONP requests which cannot use HTTP headers to send access tokens.
  3. OAuth 2: the access token is obtained by the consumer from an authorization server and sent to the API server via HTTP Bearer Tokens, according to the OAuth2 protocol.

Global Configuration of AuthMethods and RateLimiter

This template provide global configuration to set your application supported authMethods. You can find global configuration from app\config\params.php. Set your supported authMethods and RateLimiter from this file.

Example use in behaviors looks like this

Ratelimiter

To enable your ratelimiter configuration, please follow official guide from Yii documentation.

Auth Scenario

This template already have basic endpoint that you can use to start your REST-API. Such as:

Endpoint Type Usage
https://YOUR-API-URL/ GET list all post created
https://YOUR-API-URL/view?id={id} GET View a post
https://YOUR-API-URL/login POST Login with username and password
https://YOUR-API-URL/signup POST Signup with username, email and password
https://YOUR-API-URL/v1/post GET List all post created
https://YOUR-API-URL/v1/post/create POST Create a new post (title, body)
https://YOUR-API-URL/v1/post/update?id={id} PUT / PATCH Update a post (title, body)
https://YOUR-API-URL/v1/post/delete?id={id} DELETE Delete a post
https://YOUR-API-URL/v1/post/view?id={id} GET View a post

Access Token Management

This application manage token via access_token table. Access Token have certain expiration based on $tokenExpiration value. Default Token Expiration are in seconds.

In certain case you want to make a token expire before given tokenExpiration. Use method to achieve it.

Or you want to make all tokens from certain user expire, use method to achieve it.

API versioning

This template give you versioning scenario based on module application. In Yii2 a module are self-contained software units that consist of model, views, controllers and other supporting components. This template already have v1 module, it means all of endpoint for API v1 created in this module. When you publish a new API version (that break backward compatibility / BBC), you can create a new module. For more information create a module, you can visit this Yii2 Guide on Creating Module.

TODO

Feel free to contribute if you have any idea.

Creator

This Template was created by and is maintained by Heru Arief Wijaya.


All versions of yii2-rest-api-template with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version ~2.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hoaaah/yii2-rest-api-template contains the following files

Loading the files please wait ....