Code Monkey home page Code Monkey logo

exampleproductapi's Introduction

ExampleProductApi


Genel Bakış

ExampleProductApi, kullanıcıların ürün bilgilerini yönetmelerine olanak tanıyan bir RESTful API'dir.

Ne Yaptık?

  • Mail gönderme işlemi için Laravel Mail yapısı ve Event/Listener Yapısını kullandık.
  • Action Log kayıtları için Laravel Observer yapısını kullandık.
  • Aşırı yüklenmeyi ve Botları engellemek adına Laravel RateLimiter yapısını kullandık.
  • Api validation işlemleri için Laravel Request yapısını kullandık.
  • Api response işlemleri için Laravel Resource yapısını kullandık.

Özellikler

  • Ürün Listeleme: Kullanıcılar, tüm ürünleri listeleyebilirler.
  • Ürün Detayları: Her ürünün detaylı bilgilerini görüntüleyebilirler.
  • Ürün Ekleme: Yeni ürünler ekleyebilirler.
  • Ürün Güncelleme: Var olan ürünleri güncelleyebilirler.
  • Ürün Silme: Ürünleri silebilirler.

Kimlik Doğrulama

API, Login yapıldıktan sonra verilen token ile kimlik doğrulanır. Her isteğin, Authorization başlığı ile doğrulanması gerekmektedir.

Örnek:

GET /api/products
Authorization: Bearer your-access-token //Varsayılan Token Test User için: your-access-token

Kurulum


ExampleProductApi

Kurulum

API'yi kullanabilmek için aşağıdaki adımları izleyin:

1. Gerekli Bağımlılıklar:

- PHP 7.3 veya daha üstü.
- [Composer](https://getcomposer.org/) yüklü olmalı.

2. Depoyu Klonla:

git clone https://github.com/kullaniciadi/my-api.git

3. Composer ile Bağımlılıkları Yükle:

composer install

4. Ortam Dosyasını Ayarla:

  • .env.example dosyasını .env olarak kopyalayın ve gerekli bilgileri doldurun.

5. Veritabanını Oluştur:

php artisan migrate

6. Veritabanı Örnek Verileri Oluştur:

   php artisan db:seed

7. Sunucuyu Çalıştır:

   php artisan serve

8. Dökümantasyon sayfası:

 http://localhost:8000/docs

Api Uç Noktaları



Authentication


Login

POST /api/login

Eğer kullanıcı adı ve şifre doğru ise, kullanıcıya bir token verilir.

Parametre Tip Açıklama
email string Gerekli. Kullanıcı adı
password string Gerekli. Kullanıcı şifresi

Örnek İstek

POST /api/login
Content-Type: application/json

{
  "email": "[email protected]",
    "password": "password"
}

Örnek Cevap

{
  "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9"
}

Register

POST /api/login

Eğer name parametresi dolu ise Yeni bir kullanıcı oluşturur.

Parametre Tip Açıklama
name string Gerekli. Kullanıcı adı
email string Gerekli. Kullanıcı emaili
password string Gerekli. Kullanıcı şifresi

Örnek İstek

POST /api/login
Content-Type: application/json

{
  "name": "Another Test User",
  "email": "[email protected]"
    "password": "password"
}

Örnek Cevap

{
  "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9",
}

Products


Ürün Ekleme

POST /api/products

Yeni bir ürün ekler. Ve Yapılan işlemle Alakalı kullanıcıya bir mail gönderir. Yapılan işlemi loglar.

Parametre Tip Açıklama
name string Gerekli. Ürün adı
price number Gerekli. Ürün fiyatı
type enum['goods','services'] Gerekli. Ürün türü
status enum[1,0] Gerekli. Ürün durumu

Örnek İstek

POST /api/products
Content-Type: application/json
Authorization: Bearer your-access-token

{
    "name":"Product Name",
    "price":99.90,
    "status":1,
    "type":"goods"
}

Örnek Cevap

{
    "message": "Products retrieved successfully!",
    "status": "success",
    "data": {
        "name": "Product Name",
        "price": 99.9,
        "status": 1,
        "type": "goods",
        "user": "Test User | [email protected]",
        "detail": {
            "href": "http://localhost:8000/api/products/22",
            "method": "GET"
        }
    }
}

Ürün Listeleme

GET /api/products

Tüm ürünleri listeler.

Parametre Tip Açıklama
per_page number Opsiyonel. Sayfa başına ürün sayısı, Varsayılan:10
page number Opsiyonel. Sayfa numarası
name string Opsiyonel. Ürün adına göre filtreleme
user_name string Opsiyonel. Ürün sahibinin adına göre filtreleme
user_email string Opsiyonel. Ürün sahibinin emailine göre filtreleme
status enum[1,0] Opsiyonel. Ürün durumuna göre filtreleme, Varsayılan:1

Örnek İstek

GET /api/products
Content-Type: application/json
Authorization: Bearer yout-access-token
{
"per_page": 15,
"page": 1,
"name": "test",
"user_name": "test",
"user_email": "test",
"status": 1
}

Örnek Cevap

{
    "message": "Products retrieved successfully!",
    "status": "success",
    "data": [
        {
            "name": "Test Product",
            "price": "10.99",
            "status": 1,
            "type": "goods",
            "user": "Test User | [email protected]",
            "details": {
                "href": "http://localhost:8000/api/products/1",
                "method": "GET"
            }
        },
        {
            "name": "Ms. Mathilde Nicolas V",
            "price": "82.93",
            "status": 1,
            "type": "goods",
            "user": "Tanya Grady | [email protected]",
            "details": {
                "href": "http://localhost:8000/api/products/2",
                "method": "GET"
            }
        },
        {
            "name": "Wayne Konopelski",
            "price": "134.27",
            "status": 1,
            "type": "goods",
            "user": "Abraham O'Keefe | [email protected]",
            "details": {
                "href": "http://localhost:8000/api/products/3",
                "method": "GET"
            }
        },
        {
            "name": "Roberta Cruickshank",
            "price": "125.65",
            "status": 1,
            "type": "goods",
            "user": "Reyes Reichel | [email protected]",
            "details": {
                "href": "http://localhost:8000/api/products/4",
                "method": "GET"
            }
        },
        {
            "name": "Benjamin Bashirian",
            "price": "95.81",
            "status": 1,
            "type": "services",
            "user": "Miss Luna Hermiston MD | [email protected]",
            "details": {
                "href": "http://localhost:8000/api/products/5",
                "method": "GET"
            }
        },
        {
            "name": "Kayden McKenzie",
            "price": "34.10",
            "status": 1,
            "type": "goods",
            "user": "Jaren Bernhard | [email protected]",
            "details": {
                "href": "http://localhost:8000/api/products/6",
                "method": "GET"
            }
        },
        {
            "name": "Prof. Claudine Dooley V",
            "price": "80.98",
            "status": 1,
            "type": "goods",
            "user": "Dr. Watson Senger | [email protected]",
            "details": {
                "href": "http://localhost:8000/api/products/7",
                "method": "GET"
            }
        },
        {
            "name": "Shaina Thiel",
            "price": "133.03",
            "status": 1,
            "type": "goods",
            "user": "Jordane Hamill | [email protected]",
            "details": {
                "href": "http://localhost:8000/api/products/9",
                "method": "GET"
            }
        },
        {
            "name": "Junius Bayer Sr.",
            "price": "19.43",
            "status": 1,
            "type": "services",
            "user": "Reyes Reichel | [email protected]",
            "details": {
                "href": "http://localhost:8000/api/products/13",
                "method": "GET"
            }
        },
        {
            "name": "Deangelo Erdman MD",
            "price": "97.44",
            "status": 1,
            "type": "goods",
            "user": "Miss Billie Kilback | [email protected]",
            "details": {
                "href": "http://localhost:8000/api/products/15",
                "method": "GET"
            }
        }
    ],
    "meta": {
        "pagination": {
            "total": 15,
            "count": 10,
            "per_page": 10,
            "current_page": 1,
            "total_pages": 2,
            "links": {
                "next": "http://localhost:8000/api/products?page=2",
                "previous": null
            }
        }
    }
}

Ürün Detayları

GET /api/products/{id}

Ürün detaylarını gösterir.

Örnek İstek

GET /api/products/1
Content-Type: application/json
Authorization: Bearer your-access-token

Örnek Cevap

{
    "message": "Product retrieved successfully!",
    "status": "success",
    "data": {
        "product_id": 1,
        "name": "Test Product",
        "price": "10.99",
        "status": 1,
        "type": "goods",
        "user": {
            "name": "Test User",
            "email": "[email protected]",
            "id": 1
        },
        "created_at": "2024-01-21T00:13:56.000000Z",
        "updated_at": "2024-01-21T00:13:56.000000Z",
        "logs": [
            {
                "id": 1,
                "data": {
                    "id": 1,
                    "name": "Test Product",
                    "type": "goods",
                    "price": "10.99",
                    "status": 1,
                    "user_id": 1,
                    "created_at": "2024-01-21T00:13:56.000000Z",
                    "deleted_at": null,
                    "updated_at": "2024-01-21T00:13:56.000000Z"
                },
                "user": "Test User | [email protected]",
                "action": "created",
                "created_at": "2024-01-21T00:14:05.000000Z",
                "updated_at": "2024-01-21T00:14:05.000000Z"
            }
        ]
    },
    "links": {
        "self": "http://localhost:8000/api/products/1"
    }
}

Ürün Güncelleme

PUT /api/products/{id}

veya

PATCH /api/products/{id}

Ürün bilgilerini günceller. Yapılan işlemi loglar.

Parametre Tip Açıklama
name string Opsiyonel. Ürün adı
price number Opsiyonel. Ürün fiyatı
type enum['goods','services'] Opsiyonel. Ürün türü
status enum[1,0] Opsiyonel. Ürün durumu

Örnek İstek

PUT /api/products/1
Content-Type: application/json
Authorization: Bearer your-access-token

{
"name":"Product Name Changed",
"price":45.67,
"status":0,
"type":"services"
}

Örnek Cevap

{
    "message": "Product retrieved successfully!",
    "status": "success",
    "data": {
        "product_id": 12,
        "name": "Product Name Changed",
        "price": 45.67,
        "status": 0,
        "type": "services",
        "user": {
            "name": "Jaren Bernhard",
            "email": "[email protected]",
            "id": 2
        },
        "created_at": "2024-01-21T00:14:01.000000Z",
        "updated_at": "2024-01-21T00:40:00.000000Z",
        "logs": [
            {
                "id": 29,
                "data": {
                    "id": 12,
                    "name": "Dr. Jamey Batz",
                    "type": "services",
                    "price": 45.67,
                    "status": 0,
                    "user_id": 2,
                    "created_at": "2024-01-21T00:14:01.000000Z",
                    "deleted_at": null,
                    "updated_at": "2024-01-21T00:40:00.000000Z"
                },
                "user": "Test User | [email protected]",
                "action": "updated",
                "created_at": "2024-01-21T00:40:00.000000Z",
                "updated_at": "2024-01-21T00:40:00.000000Z"
            },
            {
                "id": 30,
                "data": {
                    "id": 12,
                    "name": "Dr. Jamey Batz",
                    "type": "services",
                    "price": 45.67,
                    "status": 0,
                    "user_id": 2,
                    "created_at": "2024-01-21T00:14:01.000000Z",
                    "deleted_at": null,
                    "updated_at": "2024-01-21T00:40:00.000000Z"
                },
                "user": "Test User | [email protected]",
                "action": "updated",
                "created_at": "2024-01-21T00:40:06.000000Z",
                "updated_at": "2024-01-21T00:40:06.000000Z"
            },
            {
                "id": 32,
                "data": {
                    "id": 12,
                    "name": "Product Name Changed",
                    "type": "services",
                    "price": 45.67,
                    "status": 0,
                    "user_id": 2,
                    "created_at": "2024-01-21T00:14:01.000000Z",
                    "deleted_at": null,
                    "updated_at": "2024-01-21T00:40:00.000000Z"
                },
                "user": "Test User | [email protected]",
                "action": "updated",
                "created_at": "2024-01-21T00:54:34.000000Z",
                "updated_at": "2024-01-21T00:54:34.000000Z"
            }
        ]
    },
    "links": {
        "self": "http://localhost:8000/api/products/12"
    }
}

Ürün Silme

DELETE /api/products/{id}

Ürünü siler.

Örnek İstek

DELETE /api/products/1
Content-Type: application/json
Authorization: Bearer your-access-token

Örnek Cevap

{
    "message": "Product deleted!",
    "status": "success"
}

exampleproductapi's People

Contributors

moradchalaby avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.