-

- -

Wednesday, February 24, 2021

Code Igniter 3 REST Controller Project With Sqlite



1. Startup Project

This project is extended from the original tutorial at :

https://erthru.medium.com/membuat-restful-api-menggunakan-framework-codeigniter-3-f350755b1274
and
https://erthru.medium.com/membuat-restful-api-menggunakan-framework-codeigniter-3-part-2-163cadb32e3a

The author has provided a completed project codes at:
https://github.com/erthru/restCI
or
https://drive.google.com/file/d/1tYrLlnPb4Gc-9769LyoLOcYcVKf2tYl4/view?usp=sharing




2. Download codes

Download the code from the source at Step 1 above.




3. Upload codes

Upload the zip file to your server, extract the content and rename the folder as "restci".




4. Edit database configuration

Go into restci/application/config/ and edit the file database.php as follows:




5. Create Database

note: it is recommended to use DB Browser application to create the database. The application can be downloaded from https://sqlitebrowser.org/dl/




6. Test Web Request

You should get a json output that shows no record in the database.




7. Test POST Request

Use a REST Client like POSTMAN to send POST Request according to the following settings:




8. You should get a success response as follows:




9.Repeat Step 7

go to the url {{your serverpath}}/restci/index.php/person
Now you get the following json output:
{"status":200,"error":false,"person":[{"id":1,"name":"suprianto","address":"jln testing","phone":123}]}




10.Optional

If you want to hide the index.php string in the url, you can put .htaccess file in the restci folder. Put the following codes into the file. This requires Apache mod_rewrite enabled.

File: restci/.htaccess

Now you can use the following url {{your serverpath}}//restci/person


11.Appendix

File: restci/application/controllers/TestApi.php

Sql Command: Person

File: restci/application/models/PersonM.php

No comments:

Post a Comment