Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction
The CodeIgniter RESTful API is a set of simple, modular helpers that can be easily
integrated into your CodeIgniter projects, allowing you to create customizable
RESTful APIs that suit all your needs. The package includes helpers for database
manipulation, JSON Web Token generation, validation and signing, authentication
methods, methods for accessing resources using a URI, as well as some utility
methods that will help streamline your workflow.
Requirements
PHP: 5.3.7 or greater
CodeIgniter: 3.1.5 or greater
Installation
1. Copy and paste all the files from application to the corresponding directory in
your application.
2. Copy and paste the config.example.ini file outside your application folder
or create yours, based on the example provided. Remember to name your file
config.ini or rename the sample provided.
3. Create your own secret key and update config.ini to be completely secure.
4. (Optional) Copy and paste the .example.htaccess file and tweak it to your
liking. Remember to rename it to .htaccess.
5. (Recommended) Enable HTTPS for your server for maximum security.
Contents
The API is made up of a set of helpers, each one serving a different purpose. Click on
each helper below to read about its functionality.
error_code
request
database
jwt
auth
rest_api
error_code
Contains values for various error codes. The codes are mostly matched to HTTP
status codes, but some of them might not be perfect matches. The error codes are
stored as global variables.
request
Contains a single method for retrieving the body of the current request.
database
Contains multiple methods for connecting and retrieving information from the
database.
jwt
Heavily based on this implementation, the JWT helper allows for the creation of
JSON Web Tokens. The secret key provided in config.ini will be used to sign the
token.
auth
Contains multiple methods used for authorization, authorization validation and usage
with JSON Web Tokens in cookies.
rest-api
All helpers are loaded in the __construct() method of the Api class. Certain
variables are also instantiated to be used for the API's requests.
The index() method is an empty method returning an error message, when
no resource is specified in the request in the form of a URI.
The users($param) method maps the different API methods to HTTP
methods (CREATE = POST, READ = GET, UPDATE = PUT, DELETE =
DELETE) and uses the various helpers and class variables to provide a sample
RESTful API implementation.
The login($param) method allows for the authorization of a user (needed to
update or delete a resource matched to his/her username).
License
The project is licensed under the MIT license.