Plats API Documentation

Base URL:

https://sahladelivery.com/les_plats/api_plats.php

This API allows you to manage restaurant dishes (plats).

Supported operations:


1. Get All Plats

GET /les_plats/api_plats.php

Returns all active plats.

Example Response

[
 {
  "id": 1,
  "nom": "Pizza",
  "prix": 1200,
  "id_resto": 2,
  "img": "171234234_pizza.jpg",
  "actif": 1
 }
]

2. Get Plat By ID

GET /les_plats/api_plats.php?id=1

Example Response

{
 "id": 1,
 "nom": "Pizza",
 "prix": 1200,
 "id_resto": 2,
 "img": "pizza.jpg"
}

3. Get Plats By Restaurant (id_resto)

GET /les_plats/api_plats.php?id_resto=2

This endpoint allows you to retrieve all active plats that belong to a specific restaurant using id_resto.

Query Parameters

Parameter Type Required Description
id_resto number Yes ID of the restaurant

Example Request

GET /les_plats/api_plats.php?id_resto=2

Example Response

[
 {
  "id": 3,
  "nom": "Burger",
  "prix": 900,
  "id_resto": 2,
  "img": "171234222_burger.jpg",
  "actif": 1
 },
 {
  "id": 4,
  "nom": "Tacos",
  "prix": 850,
  "id_resto": 2,
  "img": "171234223_tacos.jpg",
  "actif": 1
 }
]

4. Create Plat

POST /les_plats/api_plats.php

Form Data

Field Type Description
nom string Name of the dish
prix number Dish price
id_resto number Restaurant ID
img file Dish image (optional)

Example Response

{
 "success": true,
 "message": "Plat created",
 "id": 15,
 "img": "171234234_pizza.jpg"
}

5. Update Plat

PUT /les_plats/api_plats.php?id=1

If using HTML forms send:

POST /les_plats/api_plats.php?id=1&_method=PUT

Fields

Field Type Description
nom string Dish name
prix number Dish price
id_resto number Restaurant ID
img file Dish image (optional)

Example Response

{
 "success": true,
 "message": "Plat updated",
 "id": 1,
 "img": "newpizza.jpg"
}

6. Delete Plat

DELETE /les_plats/api_plats.php?id=1

This API does not permanently delete the plat.

It performs a soft delete by setting:

actif = 0

Example Response

{
 "success": true,
 "message": "Plat deleted"
}

Status Codes

Code Description
200 Success
400 Bad Request
404 Plat Not Found
405 Method Not Allowed