This is a simple laravel API which includes API versioning (v1 and v2).
- First, clone this repo
- CD into the directory
- Run composer install
- Run php artisan key:generate
- Run table migrations php artisan migrate
- Seed the database with some random data php artisan db:seed
- Run php artisan serve
-
Fetch index of all data in Person table with pagination
localhost:8000/api/v1/people
Method GET -
Fetch single data
localhost:8000/api/v1/person/5
Method GET
Sample response
{
"data": {
"id": 5,
"first_name": "Lenna",
"last_name": "Jacobs",
"phone": "1-578-480-5526 x210",
"email": "sporer.prudence@example.net",
"country": "Cocos (Keeling) Islands",
"created_at": "2020-11-07T20:10:56.000000Z",
"updated_at": "2020-11-07T20:10:56.000000Z"
}
}
- Store new data
localhost:8000/api/v1/person
Method POST
You can pass this in form-data of postman.
{
"first_name":
"last_name":
"email" :
"phone" :
"country" :
}
- Update a single record
localhost:8000/api/v1/person/1
Method PUT
Sample Body
{
"first_name" : "Nnaemeka",
"last_name" : "Nweke",
"phone" : "1234567890",
"email" : "nnaemeka@example.com",
"country" : "Nigeria"
}
- Delete a single record
localhost:8000/api/v1/person/1
Method DELETE
- Fetch single data
localhost:8000/api/v2/person/1
Method GET
Sample response
{
"data": {
"full_name": "Nnaemeka Nweke",
"phone": "1234567890",
"email": "nnaemeka@example.com",
"country": "Nigeria"
}
}