# CodeIgniter 4 Application Starter ## What is CodeIgniter? CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure. More information can be found at the [official site](https://codeigniter.com). This repository holds a composer-installable app starter. It has been built from the [development repository](https://github.com/codeigniter4/CodeIgniter4). More information about the plans for version 4 can be found in [CodeIgniter 4](https://forum.codeigniter.com/forumdisplay.php?fid=28) on the forums. The user guide corresponding to the latest version of the framework can be found [here](https://codeigniter4.github.io/userguide/). ## Installation & updates `composer create-project codeigniter4/appstarter` then `composer update` whenever there is a new release of the framework. When updating, check the release notes to see if there are any changes you might need to apply to your `app` folder. The affected files can be copied or merged from `vendor/codeigniter4/framework/app`. ## Setup Copy `env` to `.env` and tailor for your app, specifically the baseURL and any database settings. ## Important Change with index.php `index.php` is no longer in the root of the project! It has been moved inside the *public* folder, for better security and separation of components. This means that you should configure your web server to "point" to your project's *public* folder, and not to the project root. A better practice would be to configure a virtual host to point there. A poor practice would be to point your web server to the project root and expect to enter *public/...*, as the rest of your logic and the framework are exposed. **Please** read the user guide for a better explanation of how CI4 works! ## Repository Management We use GitHub issues, in our main repository, to track **BUGS** and to track approved **DEVELOPMENT** work packages. We use our [forum](http://forum.codeigniter.com) to provide SUPPORT and to discuss FEATURE REQUESTS. This repository is a "distribution" one, built by our release preparation script. Problems with it can be raised on our forum, or as issues in the main repository. ## Server Requirements PHP version 7.4 or higher is required, with the following extensions installed: - [intl](http://php.net/manual/en/intl.requirements.php) - [mbstring](http://php.net/manual/en/mbstring.installation.php) > **Warning** > The end of life date for PHP 7.4 was November 28, 2022. If you are > still using PHP 7.4, you should upgrade immediately. The end of life date > for PHP 8.0 will be November 26, 2023. Additionally, make sure that the following extensions are enabled in your PHP: - json (enabled by default - don't turn it off) - [mysqlnd](http://php.net/manual/en/mysqlnd.install.php) if you plan to use MySQL - [libcurl](http://php.net/manual/en/curl.requirements.php) if you plan to use the HTTP\CURLRequest library # api-ci4-customers-sqlite3
API for creating customers, their cars, their addresses, creating services and employees. Creation of customer vehicle maintenance with Codeigniter 4. The API provides registration and authentication.
Features
- Register
- Login
- CRUD Customers
- CRUD Cars customers
- CRUD Address customers
- CRUD Employees
- CRUD Services
- CRUD Maintenance cars
- CRUD Services Maintenance cars association
Server Requirements
- Developed PHP 8.2.7 and Codeigniter 4.4.4
- The following extensions need to be enabled:
- intl
- mbstring
- json
Installation
1 - Install the project using composer (requires Composer):
composer create-project luciocodeigniter/api-ci4-car-workshop
2 - Rename the sh .env-exemple.txt
file to .env
which can be found in the project root
3 - Place the information in the .env
file as per the following example:
#-------------------------------------------------------------------- # ENVIRONMENT #-------------------------------------------------------------------- CI_ENVIRONMENT = development #-------------------------------------------------------------------- # APP #-------------------------------------------------------------------- app.baseURL = 'https://exemplo.com/' app.indexPage = '' #-------------------------------------------------------------------- # DATABASE #-------------------------------------------------------------------- database.default.hostname = localhost database.default.database = db-name database.default.username = db-user database.default.password = db-password database.default.DBDriver = MySQLi database.default.DBPrefix = database.default.port = 3306 #-------------------------------------------------------------------- # JWT Authenticator #-------------------------------------------------------------------- authjwt.keys.default.0.secret = oGPvp9lLkgTvcqlVIU3rJE46uJmedapcW3EJ6cr/9gw=
Creating and populating tables in the database.
1 - At the root of the project, open the terminal and run the following command:
php spark api:init
2 . If you want to reset the database to its original state, simply run the following command in the root of the project:
php spark api:reset
3 - If you want to change the number of records to be created with seeders, simply change the TOTAL_STEPS
constant within each file, which can be found in app\Database\Seeds
:
//... /** * How many records do you want to create */ private const TOTAL_STEPS = 100; //<---- Change here //..
Registering on the application
1 . Send a POST
request to https://exemplo.com/api/register
If the request was validated, you should see the access_token in the response:
{ "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI8SXNzdWVyIG9mIHRoZSBKV1Q-Iiwic3ViIjoiMSIsImlhdCI6MTcwNjMxMDI5NSwiZXhwIjoxNzA2MzEzODk1fQ.G8SaDs_vaMqFnzELllLbfErKSUvYiofNoGzhMYQkqUg" }
When making all future requests to the API, the client should send the JWT in the Authorization header as a Bearer token.
Authenticating in the application
1 . Send a POST
request to https://exemplo.com/api/login
If the request was validated, you should see the access_token in the response:
{ "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI8SXNzdWVyIG9mIHRoZSBKV1Q-Iiwic3ViIjoiMSIsImlhdCI6MTcwNjMxMDI5NSwiZXhwIjoxNzA2MzEzODk1fQ.G8SaDs_vaMqFnzELllLbfErKSUvYiofNoGzhMYQkqUg" }
When making all future requests to the API, the client should send the JWT in the Authorization header as a Bearer token.
- Customers endpoints
List all
GET https://exemplo.com/api/customers
Get single
GET https://exemplo.com/api/customers/1
Create
POST https://exemplo.com/api/customers
Update
PUT or PATCH https://exemplo.com/api/customers/1
Delete
DELETE https://exemplo.com/api/customers/1
- Others endpoints
https://exemplo.com/api/cars https://exemplo.com/api/employees https://exemplo.com/api/services https://exemplo.com/api/maintenance https://exemplo.com/api/maintenance-services
0 commit comments