rizkijanuarr / laravel-11-api

Modul pembuatan restful api sederhana

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Restful API Laravel 11

Daftar Isi

Instalasi

Langkah-langkah untuk menginstal Restful API Laravel 11 ini:

  1. Clone repositori ini.
    git clone git@github.com:rizkijanuarr/laravel-11-api.git
  2. Masuk ke direktori proyek.
    cd laravel-11-api
  3. Copy .env.example to .env
    cp .env.example .env
  4. Install Composer.
    composer install
  5. Generate App Key.
    php artisan key:generate
  6. Konfigurasi Database on file .env
    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=laravel-11-api
    DB_USERNAME=root
    DB_PASSWORD=sesuaikan
  7. Storage link.
    php artisan storage:link
  8. Migration ke Database.
    php artisan migrate
  9. Jalankan web server.
    php artisan serve

Routing

-   http://127.0.0.1:8000/api/v1/posts || GET ✅
-   http://127.0.0.1:8000/api/v1/posts || STORE ✅
-   http://127.0.0.1:8000/api/v1/posts/1 || SHOW ✅
-   http://127.0.0.1:8000/api/v1/posts/1 || UPDATE ✅
-   http://127.0.0.1:8000/api/v1/posts/1 || DELETE ✅

Fitur

  1. GET

    {
        "success": true,
        "message": "List Data Posts",
        "data": {
            "current_page": 1,
            "data": [],
            "first_page_url": "http://127.0.0.1:8000/api/v1/posts?page=1",
            "from": null,
            "last_page": 1,
            "last_page_url": "http://127.0.0.1:8000/api/v1/posts?page=1",
            "links": [
                {
                    "url": null,
                    "label": "« Previous",
                    "active": false
                },
                {
                    "url": "http://127.0.0.1:8000/api/v1/posts?page=1",
                    "label": "1",
                    "active": true
                },
                {
                    "url": null,
                    "label": "Next »",
                    "active": false
                }
            ],
            "next_page_url": null,
            "path": "http://127.0.0.1:8000/api/v1/posts",
            "per_page": 5,
            "prev_page_url": null,
            "to": null,
            "total": 0
        }
    }
  2. STORE

    Masuk ke dalam tab (Body) dan pilih (form-data)

    KEY TYPE VALUE
    image file Pilih gambar dari komputer
    title text Citra Yudisium, yay!
    content text Yayy, kerennn!
    {
        "success": true,
        "message": "Data Post Berhasil Ditambahkan!",
        "data": {
            "image": "http://127.0.0.1:8000/storage/posts/b20chVL3TBGoRVDHZNXFiqlenfrPH4tosA7TkPq7.png",
            "title": "Citra Yudisium, yay!",
            "content": "Yayyy kerennn!",
            "updated_at": "2024-06-25T08:14:50.000000Z",
            "created_at": "2024-06-25T08:14:50.000000Z",
            "id": 1
        }
    }
  3. SHOW

    {
        "success": true,
        "message": "Detail Data Post!",
        "data": {
            "id": 1,
            "image": "http://127.0.0.1:8000/storage/posts/b20chVL3TBGoRVDHZNXFiqlenfrPH4tosA7TkPq7.png",
            "title": "Citra Yudisium, yay!",
            "content": "Yayyy kerennn!",
            "created_at": "2024-06-25T08:14:50.000000Z",
            "updated_at": "2024-06-25T08:14:50.000000Z"
        }
    }
  4. UPDATE

    Masuk ke dalam tab (Body) dan pilih (form-data)

    KEY TYPE VALUE
    image file Pilih gambar dari komputer
    title text Citra Yudisium, yay! - Update
    content text Yayy, kerennn! - Update
    _method text PUT
    {
        "success": true,
        "message": "Data Post Berhasil Diubah!",
        "data": {
            "id": 1,
            "image": "http://127.0.0.1:8000/storage/posts/b20chVL3TBGoRVDHZNXFiqlenfrPH4tosA7TkPq7.png",
            "title": "Citra Yudisium, yay! - Update",
            "content": "Yayyy kerennn! - Update",
            "created_at": "2024-06-25T08:14:50.000000Z",
            "updated_at": "2024-06-25T08:56:23.000000Z"
        }
    }
  5. DELETE

    {
        "success": true,
        "message": "Data Post Berhasil Dihapus!",
        "data": null
    }

Kontak

Jika Anda ingin menghubungi saya, Anda dapat mengirim email ke rzkjanuarr@gmail.com.

About

Modul pembuatan restful api sederhana


Languages

Language:PHP 62.2%Language:Blade 37.5%Language:JavaScript 0.3%