ExampleProductApi, kullanıcıların ürün bilgilerini yönetmelerine olanak tanıyan bir RESTful API'dir.
- 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.
- Ü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.
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
- Gerekli Bağımlılıklar
- Depoyu Klonla
- Composer ile Bağımlılıkları Yükle
- Ortam Dosyasını Ayarla
- Veritabanını Oluştur
- Veritabanı Örnek Verileri Oluştur
- Sunucuyu Çalıştır
- Dökümantasyon sayfası
API'yi kullanabilmek için aşağıdaki adımları izleyin:
- PHP 7.3 veya daha üstü.
- [Composer](https://getcomposer.org/) yüklü olmalı.
git clone https://github.com/kullaniciadi/my-api.git
composer install
.env.example
dosyasını.env
olarak kopyalayın ve gerekli bilgileri doldurun.
php artisan migrate
php artisan db:seed
php artisan serve
http://localhost:8000/docs
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 |
POST /api/login
Content-Type: application/json
{
"email": "[email protected]",
"password": "password"
}
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9"
}
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 |
POST /api/login
Content-Type: application/json
{
"name": "Another Test User",
"email": "[email protected]"
"password": "password"
}
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9",
}
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 |
POST /api/products
Content-Type: application/json
Authorization: Bearer your-access-token
{
"name":"Product Name",
"price":99.90,
"status":1,
"type":"goods"
}
{
"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"
}
}
}
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 |
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
}
{
"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
}
}
}
}
GET /api/products/{id}
Ürün detaylarını gösterir.
GET /api/products/1
Content-Type: application/json
Authorization: Bearer your-access-token
{
"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"
}
}
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 |
PUT /api/products/1
Content-Type: application/json
Authorization: Bearer your-access-token
{
"name":"Product Name Changed",
"price":45.67,
"status":0,
"type":"services"
}
{
"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"
}
}
DELETE /api/products/{id}
Ürünü siler.
DELETE /api/products/1
Content-Type: application/json
Authorization: Bearer your-access-token
{
"message": "Product deleted!",
"status": "success"
}