Proyek ini dibuat untuk membantu kalian dalam belajar penggunaan RestAPI (Creating RestAPI or Consume API). Terlepas itu pula proyek ini juga bisa kalian kembangkan untuk pengembangan yang lebih lanjut lagi.
- End Point Utama : http://laravel-api.test/api/v1/
- Resource Customers : http://laravel-api.test/api/v1/customers
- Resource Customer : http://laravel-api.test/api/v1/customers/1
- Resource Customers Params : http://laravel-api.test/api/v1/customers?postalCode[lt]=50000
- Resource Invoices : http://laravel-api.test/api/v1/invoices
- Resource Invoice : http://laravel-api.test/api/v1/invoices/1
- Resource Invoices Params : http://laravel-api.test/api/v1/invoices?status[ne]=B
- Resource Customers include Invoices Params : http://laravel-api.test/api/v1/customers?1&includeInvoices=true
- Resource Customer include Invoices : http://laravel-api.test/api/v1/customers/1?postalCode[lte]=50000&includeInvoices=true
- eq : Sama Dengan
- lt : Kurang Dari
- gt : Lebih Dari
- lte : Kurang Dari Sama Dengan
- gte : Lebih Dari Sama Dengan
- ne : Kurang Dari
Mengambil data tertentu dari server.
- URL:
/api/v1/{id}
- Metode: GET
- Paramter:
id
(int) - ID data yang diinginkan.
http
GET /api/v1/customers
json
{
"data": {
"id": 1,
"name": "Crona-Roberts",
"type": "B",
"email": "pmurazik@ruecker.com",
"address": "8880 Arielle Prairie",
"city": "North Austen",
"state": "Minnesota",
"postalCode": "09676-3256"
}
}
Menambahkan data baru ke server.
- URL:
/api/v1/customers
- Metode: POST
- Body:
json
{
"name": "Crona-Roberts",
"type": "B",
"email": "pmurazik@gmail.com",
"address": "8880 Arielle Prairie",
"city": "North Austen",
"state": "Minnesota",
"postalCode": "09676-3256"
}
http
POST /api/v1/customers
Content-Type: application/json
Accept: application/json
json
{
"name": "Crona-Roberts",
"type": "B",
etc...
}
json
{
"data": {
"id": 233,
"name": "Crona-Roberts",
"type": "B",
"email": "pmurazik@gmail.com",
"address": "8880 Arielle Prairie",
"city": "North Austen",
"state": "Minnesota",
"postalCode": "09676-3256"
}
}
Mengubah data baru ke server.
- URL:
/api/v1/customers/{id}
- Metode: PUT
- Body:
json
{
"name": "Crona-Roberts update",
"type": "B",
"email": "pmurazik@gmail.com",
etc...
}
http
POST /api/v1/customers/{id}
Content-Type: application/json
Accept: application/json
json
{
"name": "Crona-Roberts update",
"type": "B",
etc...
}
json
{
"data": {
"id": 1,
"name": "Crona-Roberts update",
"type": "B",
"email": "pmurazik@gmail.com",
etc...
}
}
- URL:
api/v1/invoices/bulk
- Metode: POST
- Body:
json
{
"name": "Crona-Roberts update",
"type": "B",
"email": "pmurazik@gmail.com",
etc...
}
json
[
{
"customerId": 1,
"amount": 90000,
"status": "P",
"billedDate": "2022-01-12 06:51:16",
"paidDate": "2022-01-14 06:51:16"
},
{
"customerId": 1,
"amount": 100000,
"status": "B",
"billedDate": "2019-07-24 07:53:25",
"paidDate": null
}
]
DEVABI - 2023