{"id":158,"date":"2025-06-17T12:00:49","date_gmt":"2025-06-17T12:00:49","guid":{"rendered":"https:\/\/dila.infokand23.my.id\/blog\/?p=158"},"modified":"2025-06-17T12:00:49","modified_gmt":"2025-06-17T12:00:49","slug":"tutorial-pembuatan-api-dan-testing-api-pada-laravel","status":"publish","type":"post","link":"https:\/\/dila.infokand23.my.id\/blog\/tutorial-pembuatan-api-dan-testing-api-pada-laravel\/","title":{"rendered":"TUTORIAL PEMBUATAN API DAN TESTING API PADA LARAVEL"},"content":{"rendered":"\n<p>Source Code Project: <a href=\"https:\/\/github.com\/SitiFadhilahRahmi\/API-Project-Laravel_PWEB.git\">https:\/\/github.com\/SitiFadhilahRahmi\/API-Project-Laravel_PWEB.git<\/a><\/p>\n\n\n\n<p><strong>SETUP PROJECT<\/strong><\/p>\n\n\n\n<p>Pertama buat project laravel baru, bisa melalui command prompt atau cmder, atau sejenisnya<\/p>\n\n\n\n<p>Masukkan perintah:<br><strong>composer create-project laravel\/laravel api-project<\/strong><\/p>\n\n\n\n<p>Dan tunggu hingga project selesai dibuat<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"387\" height=\"108\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-43.jpg\" alt=\"\" class=\"wp-image-159\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-43.jpg 387w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-43-300x84.jpg 300w\" sizes=\"auto, (max-width: 387px) 100vw, 387px\" \/><\/figure>\n\n\n\n<p>Selanjutnya masuk ke folder project dengan perintah<br><strong>cd api-project<\/strong><\/p>\n\n\n\n<p>Lalu jalankan project dengan perintah<br><strong>php artisan serve<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"387\" height=\"108\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-43.jpg\" alt=\"\" class=\"wp-image-160\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-43.jpg 387w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-43-300x84.jpg 300w\" sizes=\"auto, (max-width: 387px) 100vw, 387px\" \/><\/figure>\n\n\n\n<p><strong>DATABASE DAN MIGRATION<\/strong><\/p>\n\n\n\n<p>Selanjutnya adalah menyiapkan database. Buka folder project di vscode atau code editor lainnya. Lalu buka terminal dan masukkan perintah <strong>php artisan make:migration create_products_table <\/strong>untuk membuat table migrasi. Jika sudah maka akan terbuat file database\\migrations\\2025_06_17_080823_create_products_table.php.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"553\" height=\"303\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-44.jpg\" alt=\"\" class=\"wp-image-161\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-44.jpg 553w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-44-300x164.jpg 300w\" sizes=\"auto, (max-width: 553px) 100vw, 553px\" \/><\/figure>\n\n\n\n<p>Edit file tersebut menjadi:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"410\" height=\"290\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-45.jpg\" alt=\"\" class=\"wp-image-163\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-45.jpg 410w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-45-300x212.jpg 300w\" sizes=\"auto, (max-width: 410px) 100vw, 410px\" \/><\/figure>\n\n\n\n<p>Lalu jalankan migrationnya dengan perintah <strong>php artisan migrate<\/strong> pada terminal<\/p>\n\n\n\n<p><strong>MODEL<\/strong><\/p>\n\n\n\n<p>Jalankan perintah <strong>php artisan make:model Product<\/strong> untuk membuat file model baru bernama Product.php di direktori app\/Models. Sesuaikan Produck.php seperti berikut:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"354\" height=\"244\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-46.jpg\" alt=\"\" class=\"wp-image-162\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-46.jpg 354w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-46-300x207.jpg 300w\" sizes=\"auto, (max-width: 354px) 100vw, 354px\" \/><\/figure>\n\n\n\n<p><strong>API ROUTES<\/strong><\/p>\n\n\n\n<p>Buat file api.php pada folder routes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"474\" height=\"208\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-47.jpg\" alt=\"\" class=\"wp-image-164\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-47.jpg 474w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-47-300x132.jpg 300w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/figure>\n\n\n\n<p><strong>API CONTROLLER<\/strong><\/p>\n\n\n\n<p>Gunakan perintah php artisan make:controller ProductController &#8211;api untuk membuat controllernya. Filenya akan berada di folder app\\Http\\Controllers\\ProductController.php.<\/p>\n\n\n\n<p>Sesuaikan file tersebut dengan:<\/p>\n\n\n\n<div class=\"wp-block-group has-ast-global-color-5-background-color has-background is-layout-constrained wp-container-core-group-is-layout-d67366e9 wp-block-group-is-layout-constrained\" style=\"min-height:1px\">\n<p>&lt;?php<\/p>\n\n\n\n<p>namespace App\\Http\\Controllers;<\/p>\n\n\n\n<p>use Illuminate\\Http\\Request;<\/p>\n\n\n\n<p>use App\\Models\\Product;<\/p>\n\n\n\n<p>class ProductController extends Controller<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>&nbsp; &nbsp; public function index()<\/p>\n\n\n\n<p>&nbsp; &nbsp; {<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $products = Product::all();<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; return response()-&gt;json([<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;status&#8217; =&gt; &#8216;success&#8217;,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;data&#8217; =&gt; $products<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; ]);<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; public function store(Request $request)<\/p>\n\n\n\n<p>&nbsp; &nbsp; {<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $validated = $request-&gt;validate([<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;name&#8217; =&gt; &#8216;required|string|max:255&#8217;,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;description&#8217; =&gt; &#8216;required|string&#8217;,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;price&#8217; =&gt; &#8216;required|numeric|min:0&#8217;,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;stock&#8217; =&gt; &#8216;required|integer|min:0&#8217;<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; ]);<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $product = Product::create($validated);<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; return response()-&gt;json([<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;status&#8217; =&gt; &#8216;success&#8217;,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;message&#8217; =&gt; &#8216;Product created successfully&#8217;,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;data&#8217; =&gt; $product<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; ], 201);<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; public function show(Product $product)<\/p>\n\n\n\n<p>&nbsp; &nbsp; {<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; return response()-&gt;json([<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;status&#8217; =&gt; &#8216;success&#8217;,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;data&#8217; =&gt; $product<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; ]);<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; public function update(Request $request, Product $product)<\/p>\n\n\n\n<p>&nbsp; &nbsp; {<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $validated = $request-&gt;validate([<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;name&#8217; =&gt; &#8216;sometimes|string|max:255&#8217;,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;description&#8217; =&gt; &#8216;sometimes|string&#8217;,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;price&#8217; =&gt; &#8216;sometimes|numeric|min:0&#8217;,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;stock&#8217; =&gt; &#8216;sometimes|integer|min:0&#8217;<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; ]);<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $product-&gt;update($validated);<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; return response()-&gt;json([<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;status&#8217; =&gt; &#8216;success&#8217;,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;message&#8217; =&gt; &#8216;Product updated successfully&#8217;,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;data&#8217; =&gt; $product<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; ]);<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; public function destroy(Product $product)<\/p>\n\n\n\n<p>&nbsp; &nbsp; {<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $product-&gt;delete();<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; return response()-&gt;json([<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;status&#8217; =&gt; &#8216;success&#8217;,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;message&#8217; =&gt; &#8216;Product deleted successfully&#8217;<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; ]);<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>}<\/p>\n<\/div>\n\n\n\n<p><strong>API RESOURCES (DATA TRANSFORMATION)<\/strong><\/p>\n\n\n\n<p>API Resource berfungsi sebagai layer transformasi antara model Eloquent dan JSON response yang dikirim ke client sehingga dapat digunakan untuk Mengontrol format output JSON, Menyembunyikan field sensitive, Menambahkan field computed dan Membuat response yang konsisten.<\/p>\n\n\n\n<p>Buat resource menggunakan command <strong>php artisan make:resource ProductResource<\/strong><\/p>\n\n\n\n<p>File resource akan berada pada \/\/ app\/Http\/Resources\/ProductResource.php. Lalu sesuaikan file:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"343\" height=\"254\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-48.jpg\" alt=\"\" class=\"wp-image-165\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-48.jpg 343w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-48-300x222.jpg 300w\" sizes=\"auto, (max-width: 343px) 100vw, 343px\" \/><\/figure>\n\n\n\n<p>Ubah method index dan show menggunakan API Resource pada ProductController.php dan jangan lupa untuk import ProductResource menggunakan use.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"422\" height=\"191\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-49.jpg\" alt=\"\" class=\"wp-image-166\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-49.jpg 422w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-49-300x136.jpg 300w\" sizes=\"auto, (max-width: 422px) 100vw, 422px\" \/><\/figure>\n\n\n\n<p><strong>ROUTESERVICEPROVIDER<\/strong><\/p>\n\n\n\n<p>Buat provider baru dengan command <strong>php artisan make:provider RouteServiceProvider<\/strong> yang akan digunakan untuk mendaftarkan file routing api.php<\/p>\n\n\n\n<p>Lalu sesuaikan dengan code:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"452\" height=\"283\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-50.jpg\" alt=\"\" class=\"wp-image-167\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-50.jpg 452w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-50-300x188.jpg 300w\" sizes=\"auto, (max-width: 452px) 100vw, 452px\" \/><\/figure>\n\n\n\n<p><strong>VALIDASI DAN ERROR HANDLING<\/strong><\/p>\n\n\n\n<p>Buat Form Request Validation di Laravel digunakan untuk memisahkan dan mengorganisir logika validasi data input dari controller.<\/p>\n\n\n\n<p>Buat menggunakan command <strong>php artisan make:request StoreProductRequest.<\/strong><\/p>\n\n\n\n<p>File akan berada pada app\\Http\\Requests\\StoreProductRequest.php.<\/p>\n\n\n\n<p>Sesuaikan dengan:<br><img loading=\"lazy\" decoding=\"async\" width=\"361\" height=\"363\" src=\"blob:https:\/\/dila.infokand23.my.id\/f0fa2ac8-d6fd-4b89-92bd-9288ecf6eaa2\"><\/p>\n\n\n\n<p>Implementasikan pada Method Store di file Product Controller dan jangan lupa untuk import StoreProductRequest.phpnya<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"445\" height=\"176\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-51.jpg\" alt=\"\" class=\"wp-image-168\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-51.jpg 445w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-51-300x119.jpg 300w\" sizes=\"auto, (max-width: 445px) 100vw, 445px\" \/><\/figure>\n\n\n\n<p><strong>Global Exception Handler<\/strong><\/p>\n\n\n\n<p>Global Exception Handler ini akan digunakan untuk menangkap dan menangani semua exception (kesalahan) yang terjadi di aplikasi secara terpusat.<\/p>\n\n\n\n<p>Buat folder baru yaitu folder Exceptions di dalam folder app dan tambahkan file Handler.php<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"417\" height=\"333\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-52.jpg\" alt=\"\" class=\"wp-image-169\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-52.jpg 417w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-52-300x240.jpg 300w\" sizes=\"auto, (max-width: 417px) 100vw, 417px\" \/><\/figure>\n\n\n\n<p><strong>MENGAKSES API PRODUCTS DENGAN POSTMAN<\/strong><\/p>\n\n\n\n<p>Untuk melakukan pengujian menggunakan POSTMAN, download aplikasinya melalui website resmi POSTMAN dan langsung install<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"339\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-56.jpg\" alt=\"\" class=\"wp-image-173\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-56.jpg 602w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-56-300x169.jpg 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<p>Buka aplikasinya lalu klik new dan pilih HTTP. Maka akan tampil untitled request baru di sampingnya.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"339\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-53.jpg\" alt=\"\" class=\"wp-image-170\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-53.jpg 602w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-53-300x169.jpg 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<p><strong>GET &#8211; Mengambil Semua Products<\/strong><\/p>\n\n\n\n<p>Masukkan URL <a href=\"http:\/\/localhost:8000\/products\/\">http:\/\/localhost:8000\/products\/<\/a> lalu send dan lihat hasilnya<\/p>\n\n\n\n<p>Jika berhasil maka akan muncul Response <strong>200 OK<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"339\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-57.jpg\" alt=\"\" class=\"wp-image-174\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-57.jpg 602w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-57-300x169.jpg 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<p><strong>POST \u2013 Membuat Product Baru<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"339\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-54.jpg\" alt=\"\" class=\"wp-image-171\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-54.jpg 602w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-54-300x169.jpg 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<p>Akan muncul respon 201 Created jika data berhasil di POST.<\/p>\n\n\n\n<p><strong>GET &#8211; Mengambil Product Berdasarkan ID<\/strong><\/p>\n\n\n\n<p>URL: <a href=\"http:\/\/localhost:8000\/products\/%7bid%7d\">http:\/\/localhost:8000\/products\/{id}<\/a><\/p>\n\n\n\n<p>Jika id nya 1, maka akan ditampilkan data dengan id 1<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"339\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-59.jpg\" alt=\"\" class=\"wp-image-175\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-59.jpg 602w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-59-300x169.jpg 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<p><strong>PUT &#8211; Update Product<\/strong><\/p>\n\n\n\n<p>URL: <a href=\"http:\/\/localhost:8000\/products\/%7bid%7d\">http:\/\/localhost:8000\/products\/{id}<\/a><\/p>\n\n\n\n<p>Masukkan<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>&#8220;name&#8221;: &#8220;Laptop Gaming Updated&#8221;,<\/p>\n\n\n\n<p>&#8220;description&#8221;: &#8220;Laptop gaming dengan spek tinggi dan SSD 1TB&#8221;,<\/p>\n\n\n\n<p>&#8220;price&#8221;: 16500000.00,<\/p>\n\n\n\n<p>&#8220;stock&#8221;: 8<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>Di bagian body, bagian raw terlebih dahulu lalu send. Jika berhasil:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"339\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-58.jpg\" alt=\"\" class=\"wp-image-176\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-58.jpg 602w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-58-300x169.jpg 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<p><strong>DELETE &#8211; Hapus Product<\/strong><\/p>\n\n\n\n<p>URL: <a href=\"http:\/\/localhost:8000\/products\/%7bid%7d\">http:\/\/localhost:8000\/products\/{id}<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"339\" src=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-55.jpg\" alt=\"\" class=\"wp-image-172\" srcset=\"https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-55.jpg 602w, https:\/\/dila.infokand23.my.id\/blog\/wp-content\/uploads\/2025\/06\/image-55-300x169.jpg 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Source Code Project: https:\/\/github.com\/SitiFadhilahRahmi\/API-Project-Laravel_PWEB.git SETUP PROJECT Pertama buat project laravel baru, bisa melalui command prompt atau cmder, atau sejenisnya Masukkan [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":177,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-158","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/dila.infokand23.my.id\/blog\/wp-json\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dila.infokand23.my.id\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dila.infokand23.my.id\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dila.infokand23.my.id\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dila.infokand23.my.id\/blog\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":1,"href":"https:\/\/dila.infokand23.my.id\/blog\/wp-json\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":178,"href":"https:\/\/dila.infokand23.my.id\/blog\/wp-json\/wp\/v2\/posts\/158\/revisions\/178"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dila.infokand23.my.id\/blog\/wp-json\/wp\/v2\/media\/177"}],"wp:attachment":[{"href":"https:\/\/dila.infokand23.my.id\/blog\/wp-json\/wp\/v2\/media?parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dila.infokand23.my.id\/blog\/wp-json\/wp\/v2\/categories?post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dila.infokand23.my.id\/blog\/wp-json\/wp\/v2\/tags?post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}