Download the PHP package nikxphreaker/yii2-hiring-backend without Composer
On this page you can find all versions of the php package nikxphreaker/yii2-hiring-backend. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nikxphreaker/yii2-hiring-backend
More information about nikxphreaker/yii2-hiring-backend
Files in nikxphreaker/yii2-hiring-backend
Package yii2-hiring-backend
Short Description Yii 2 RESTful API
License BSD-3-Clause
Informations about the package yii2-hiring-backend
Yii 2 RESTful API
++++++++++++++++++++++++++++++++++ Yii2 RESTful API ++++++++++++++++++++++++++++++++++ This API using template from Yii-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
Install composer.
Install with git
To directory [app-name]
Setup Database
Setup database configuration from config/db.php
.
Running API
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
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
Test Using Postman
Download Postman.
Auth Scenario
This template already have basic endpoint that you can use to start your REST-API. Such as:
Endpoint | Type | Usage |
---|---|---|
https://localhost:8080/session | GET | list all session created |
https://localhost:8080/view?id={id} | POST | View a session |
https://localhost:8080/login | POST | Login with username and password (stored 3 cookies include id, username & token) |
https://localhost:8080/signup | POST | Signup with username, email and password |
https://localhost:8080/logout | This endpoint must be use if you want to clear your cookies | |
https://localhost:8080/v1/session | GET | List all session created (Must Login) |
https://localhost:8080/v1/session/create | POST | Create a new session (Must Login) |
https://localhost:8080/v1/session/update?id={id} | PUT / PATCH | Update a session (Must Login) |
https://localhost:8080/v1/session/delete?id={id} | DELETE | Delete a session (Must Login) |
https://localhost:8080/v1/session/view?id={id} | GET | View a session (Must Login) |
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://localhost:8080/v1/endpoint
.
API Scenario
Creating User
Login User
Setting token
Create Session
Edit Session
Delete Session
Viewing Detail Session
List Session
Supported Authentication
This template support 3 most used authentication. (Actually it's not me who make it, Yii2 already support it all :D ).
- 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.
- 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.
- 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.
Access Token Management
This application manage token via cookie without storing to table or data in database. Access Token have certain expiration based on $tokenExpiration value. Default Token Expiration are in seconds.
This cookies stored to your computer
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.