0% found this document useful (0 votes)
22 views26 pages

CodeIgniter REST API Setup Guide

This document summarizes the steps to create a web service API using CodeIgniter including: 1) Preparing the database and tables. 2) Setting up the CodeIgniter project folder and installing CodeIgniter and REST libraries. 3) Creating an API controller class to handle GET, POST, PUT, DELETE requests. 4) Testing the API using Postman by making requests to retrieve, add, update and delete customer records.

Uploaded by

aniftulabre
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views26 pages

CodeIgniter REST API Setup Guide

This document summarizes the steps to create a web service API using CodeIgniter including: 1) Preparing the database and tables. 2) Setting up the CodeIgniter project folder and installing CodeIgniter and REST libraries. 3) Creating an API controller class to handle GET, POST, PUT, DELETE requests. 4) Testing the API using Postman by making requests to retrieve, add, update and delete customer records.

Uploaded by

aniftulabre
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Web Service

{SERVER}
● Persiapan database dan tabel
● Persiapan aplikasi (folder project dan
instalasi Codeiginter, RESTFull)
● API
Database & Tabel
● Buat database “webservice” dan tabel
“customer” dengan struktur berikut:
Persiapan file project SERVER

Download Codeigniter (CI) terbaru
– [Link]


Buat folder dengan nama“server” pada direktori web
server (misalkan: d:\xampp\htdocs\server) dan Extract
CI ke folder tersebut
Library REST Server

Download file library restserver di:
– [Link]


Extract lalu copy kan file berikut:
codeigniter-restserver-master/application/config/[Link]
---- copy ke -------
server/application/config/[Link]

codeigniter-restserver-master/application/libraries/[Link]
---- copy ke -------
server/application/libraries/[Link]

codeigniter-restserver-master/application/libraries/REST_Controller.php
---- copy ke -------
server/application/libraries/REST_Controller.php

codeigniter-restserver-master/application/language/english/rest_controller_lang.php
---- copy ke -------
server/application/language/english/rest_controller_lang.php
Konfigurasi Database
● Modifikasi file “[Link]” pada folder
“application/config”

‘root’,
‘’,
Konfigurasi Autoload Library
● Modifikasi file “[Link]” pada folder
“application/config”, load library “database” secara default
API web service
● Buat controller dengan nama “[Link]” simpan
pada folder “application/controllers”, buat class
Api extends REST_Controller seperti berikut:
Request GET
● Tambahkan fungsi customers_get() pada class
[Link] untuk melayani request GET dari client
Request POST
● Tambahkan fungsi customers_post() pada class
[Link] untuk melayani request POST dari client
Request PUT
● Tambahkan fungsi customers_put() pada class
[Link] untuk melayani request PUT dari client
Request DELETE
● Tambahkan fungsi customers_delete() pada class
[Link] untuk melayani request DELETE dari
client
Uji Coba API (1)

Isi tabel dengan data berikut:
Uji Coba API (2)

Downlod aplikasi POSTMAN dan jalankan

[Link]
Uji Coba API - GET (1)
Request → tampilkan semua record


URL: [Link]

Method: GET

Klik tombol “Send”
Hasil Request
Uji Coba API - GET (2)
Request → tampilkan record tertentu

● URL: [Link]
● Method: GET

● Klik tombol “Params”, isikan parameter berikut: key=id,

value=6
● Klik tombol “Send”
Hasil Request
Uji Coba format Output API
(json | xml)

● URL: [Link]
● Method: GET

● Klik tombol “Params”, isikan parameter berikut:

key=format, value=json | xml (isikan salah satu)

● Klik tombol “Send”


Output format API
Uji Coba API – POST (1)
Request → insert record baru
● URL: [Link]
● Method: POST

● Klik tab “Body”, pilih “form-data”, isikan parameter berikut:

Key Value
name Joni

city Jakarta

phone 08800000000

● Klik tombol “Send”


Uji Coba API – POST (2)
2
1 6
3

7 Hasil request POST → input data ke server


Hasil POST

Record baru hasil insert


Uji Coba API – DELETE (1)
Request→ delete record
● URL: [Link]
● Method: DELETE

● Klik tab “Body”, pilih “x-www-form-urlencoded”,

isikan parameter berikut:



Key Value
id 14

– Value sesuai dengan id record yg akan di delete

● Klik tombol “Send”


Uji Coba API – DELETE (2)
2
1

3 6
4

7 Hasil request DELETE→ hapus data di server


Uji Coba API – PUT (1)
Request → update record
● URL: [Link]
● Method: PUT

● Klik tab “Body”, pilih “x-www-form-urlencoded”, isikan

parameter berikut:
Key Value
name Rina

city Semarang Field yang akan diupdate

phone 085

id 15

● Klik tombol “Send”


Uji Coba API – PUT (2)
2 1

4 3 6

7 Hasil request PUT→ update data di server

You might also like