Skip to content

Marco-Garro/PhpCatAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cat API

Start up

The web server is Apache and the database is SQLite. The project can be run with Docker.

docker compose up --build

or just:

docker compose up

DB structure

CREATE TABLE cats(
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name VARCHAR(20),
    image BLOB,,
    age INTEGER,
    WhereWasFound TEXT,
    WhereWasSeen TEXT,
    sex BOOLEAN NOT NULL CHECK (sex IN (0, 1)),
    price INTEGER,
    color VARCHAR(15),
    weight INTEGER,
    breed VARCHAR(15)
);

API

GET /CatRouter.php?id={id}

Request

Parameter Type Description
id int Cat id from the db

NOTE: If the id is not present in the db, the API will return all the cats in the db.

Response

[
  {
    "id": 1,
    "name": "Alfonso",
    "image": "test",
    "age": 4,
    "whereWasFound": "Termoli",
    "whereWasSeen": "Bari",
    "sex": true,
    "price": 5,
    "color": "Daltonico",
    "weight": 59,
    "breed":"Pastore australiano"
  }
]
Parameter Type Description
id int Cat id from the db
name string Cat name
image string Cat image encoded in base64
age int Cat age
whereWasFound string Where the cat was found
whereWasSeen string Where the Cat was seen
sex boolean cat sex
price int Cat price
color string Cat color
weight int Cat weight
breed string Cat breed

POST /CatRouter.php

Request

{
    "id": 0,
    "name": "Alfonso",
    "image": "test",
    "age": 4,
    "whereWasFound": "Termoli",
    "whereWasSeen": "Bari",
    "sex": true,
    "price": 5,
    "color": "Daltonico",
    "weight": 59,
    "breed":"Pastore australiano"
}
Parameter Type Description
id int Cat id from the db
name string Cat name
image string Cat image encoded in base64
age int Cat age
whereWasFound string Where the cat was found
whereWasSeen string Where the Cat was seen
sex boolean cat sex
price int Cat price
color string Cat color
weight int Cat weight
breed string Cat breed

Response

{
    "id": 1,
    "name": "Alfonso",
    "image": "test",
    "age": 4,
    "whereWasFound": "Termoli",
    "whereWasSeen": "Bari",
    "sex": true,
    "price": 5,
    "color": "Daltonico",
    "weight": 59,
    "breed":"Pastore australiano"  
}
Parameter Type Description
id int Cat id from the db
name string Cat name
image string Cat image encoded in base 64
age int Cat age
whereWasFound string Where the cat was found
whereWasSeen string Where the Cat was seen
sex boolean cat sex
price int Cat price
color string Cat color
weight int Cat weight
breed string Cat breed

PUT /CatRouter.php

Request

{
    "id": 1,
    "name": "Alfonso",
    "image": "test",
    "age": 4,
    "whereWasFound": "Termoli",
    "whereWasSeen": "Bari",
    "sex": true,
    "price": 5,
    "color": "Daltonico",
    "weight": 59,
    "breed":"Pastore australiano"
}

Response

{
    "id": 1,
    "name": "Alfonso",
    "image": "test",
    "age": 4,
    "whereWasFound": "Termoli",
    "whereWasSeen": "Bari",
    "sex": true,
    "price": 5,
    "color": "Daltonico",
    "weight": 59,
    "breed":"Pastore australiano"
}
Parameter Type Description
id int Cat id from the db
name string Cat name
image string Cat image encoded in base64
age int Cat age
whereWasFound string Where the cat was found
whereWasSeen string Where the Cat was seen
sex boolean cat sex
price int Cat price
color string Cat color
weight int Cat weight
breed string Cat breed

DELETE /CatRouter.php?id={id}

Request

Parameter Type Description
id int Cat id from the db

Response

{
  "deleted": true
}
Parameter Type Description
deleted boolean If the cat was deleted

Troubleshooting

if the db returns an error like:

    string(70) "SQLSTATE[HY000]: General error: 8 attempt to write a readonly database"

you need to change the permissions of the db file and the directory where it is located.

chmod 777 cats.db
chmod 777 ./src

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published