Introduction
A simple REST API in Laravel
This documentation aims to provide all the information you need to work with our API.
Authenticating requests
This API is authenticated by sending an Authorization
header with the value "Bearer <token>"
.
All authenticated endpoints are marked with a requires authentication
badge in the documentation below.
You can retrieve your token by logging in to your account.
Authentication
APIs for User Authentication
Login
This endpoint is used to login a user to the system.
Example request:
curl --request POST \
"https://rest.iankumu.com/api/v1/login" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data "{
\"email\": \"ian@gmail.com\",
\"password\": \"12345678\"
}"
const url = new URL(
"https://rest.iankumu.com/api/v1/login"
);
const headers = {
"Content-Type": "application/json",
"Accept": "application/json",
};
let body = {
"email": "ian@gmail.com",
"password": "12345678"
};
fetch(url, {
method: "POST",
headers,
body: JSON.stringify(body),
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$response = $client->post(
'https://rest.iankumu.com/api/v1/login',
[
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],
'json' => [
'email' => 'ian@gmail.com',
'password' => '12345678',
],
]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json
url = 'https://rest.iankumu.com/api/v1/login'
payload = {
"email": "ian@gmail.com",
"password": "12345678"
}
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.request('POST', url, headers=headers, json=payload)
response.json()
Example response (200, Successful Login):
{
"message": "User Login Successfully",
"access_token": "8|MgowQLkdpShwrb8AI9j1YAGmwnDjAOeE17XrP5nb",
"token_type": "Bearer"
}
Example response (401, Failed Login):
{
"message": "Invalid login credentials"
}
Received response:
Request failed with error:
Register
This endpoint is used to register a new user to the database.
Example request:
curl --request POST \
"https://rest.iankumu.com/api/v1/register" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data "{
\"name\": \"Ian\",
\"email\": \"ian@gmail.com\",
\"password\": \"12345678\"
}"
const url = new URL(
"https://rest.iankumu.com/api/v1/register"
);
const headers = {
"Content-Type": "application/json",
"Accept": "application/json",
};
let body = {
"name": "Ian",
"email": "ian@gmail.com",
"password": "12345678"
};
fetch(url, {
method: "POST",
headers,
body: JSON.stringify(body),
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$response = $client->post(
'https://rest.iankumu.com/api/v1/register',
[
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],
'json' => [
'name' => 'Ian',
'email' => 'ian@gmail.com',
'password' => '12345678',
],
]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json
url = 'https://rest.iankumu.com/api/v1/register'
payload = {
"name": "Ian",
"email": "ian@gmail.com",
"password": "12345678"
}
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.request('POST', url, headers=headers, json=payload)
response.json()
Example response (201, User Account Created):
{
"message": "User Account Created Successfully",
"access_token": "8|MgowQLkdpShwrb8AI9j1YAGmwnDjAOeE17XrP5nb",
"token_type": "Bearer"
}
Received response:
Request failed with error:
Logout
requires authentication
This endpoint is used to logout a user from the system.
Example request:
curl --request POST \
"https://rest.iankumu.com/api/v1/logout" \
--header "Authorization: Bearer <token>" \
--header "Content-Type: application/json" \
--header "Accept: application/json"
const url = new URL(
"https://rest.iankumu.com/api/v1/logout"
);
const headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json",
"Accept": "application/json",
};
fetch(url, {
method: "POST",
headers,
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$response = $client->post(
'https://rest.iankumu.com/api/v1/logout',
[
'headers' => [
'Authorization' => 'Bearer <token>',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],
]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json
url = 'https://rest.iankumu.com/api/v1/logout'
headers = {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.request('POST', url, headers=headers)
response.json()
Example response (200, Successful Logout):
{
"message": "Succesfully Logged out"
}
Received response:
Request failed with error:
Products
APIs for managing Products
Get All Products
requires authentication
This endpoint is used to fetch all products available in the database.
Example request:
curl --request GET \
--get "https://rest.iankumu.com/api/v1/products?page=1" \
--header "Authorization: Bearer <token>" \
--header "Content-Type: application/json" \
--header "Accept: application/json"
const url = new URL(
"https://rest.iankumu.com/api/v1/products"
);
const params = {
"page": "1",
};
Object.keys(params)
.forEach(key => url.searchParams.append(key, params[key]));
const headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json",
"Accept": "application/json",
};
fetch(url, {
method: "GET",
headers,
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$response = $client->get(
'https://rest.iankumu.com/api/v1/products',
[
'headers' => [
'Authorization' => 'Bearer <token>',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],
'query' => [
'page'=> '1',
],
]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json
url = 'https://rest.iankumu.com/api/v1/products'
params = {
'page': '1',
}
headers = {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.request('GET', url, headers=headers, params=params)
response.json()
Example response (200, Get All Products):
{
"data": [
{
"id": 1,
"product_name": "quo",
"product_price": "$15",
"discounted_price": "$13.5",
"discount": "$1.5",
"product_description": "Ut rerum aut deleniti eveniet ad et ullam perferendis."
},
{
"id": 2,
"product_name": "Laptop",
"product_price": "$500",
"discounted_price": "$450",
"discount": "$50",
"product_description": "This is a brand new laptop"
}
]
}
Received response:
Request failed with error:
Add Products to the Database
requires authentication
This endpoint is used to add a product to the database.
Example request:
curl --request POST \
"https://rest.iankumu.com/api/v1/products" \
--header "Authorization: Bearer <token>" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data "{
\"name\": \"Laptop\",
\"price\": 199,
\"description\": \"Nulla voluptas cumque illum iure nulla.\"
}"
const url = new URL(
"https://rest.iankumu.com/api/v1/products"
);
const headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json",
"Accept": "application/json",
};
let body = {
"name": "Laptop",
"price": 199,
"description": "Nulla voluptas cumque illum iure nulla."
};
fetch(url, {
method: "POST",
headers,
body: JSON.stringify(body),
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$response = $client->post(
'https://rest.iankumu.com/api/v1/products',
[
'headers' => [
'Authorization' => 'Bearer <token>',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],
'json' => [
'name' => 'Laptop',
'price' => 199.0,
'description' => 'Nulla voluptas cumque illum iure nulla.',
],
]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json
url = 'https://rest.iankumu.com/api/v1/products'
payload = {
"name": "Laptop",
"price": 199,
"description": "Nulla voluptas cumque illum iure nulla."
}
headers = {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.request('POST', url, headers=headers, json=payload)
response.json()
Example response (201, Add a Product):
{
"data": {
"id": 2,
"product_name": "veritatis",
"product_price": "$30",
"discounted_price": "$27",
"discount": "$3",
"product_description": "Esse cupiditate eaque qui laboriosam quis id."
}
}
Received response:
Request failed with error:
Get a Single Product
requires authentication
This endpoint is used to return a single products from the database.
Example request:
curl --request GET \
--get "https://rest.iankumu.com/api/v1/products/8" \
--header "Authorization: Bearer <token>" \
--header "Content-Type: application/json" \
--header "Accept: application/json"
const url = new URL(
"https://rest.iankumu.com/api/v1/products/8"
);
const headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json",
"Accept": "application/json",
};
fetch(url, {
method: "GET",
headers,
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$response = $client->get(
'https://rest.iankumu.com/api/v1/products/8',
[
'headers' => [
'Authorization' => 'Bearer <token>',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],
]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json
url = 'https://rest.iankumu.com/api/v1/products/8'
headers = {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.request('GET', url, headers=headers)
response.json()
Example response (200, Get a Single Product):
{
"data": {
"id": 2,
"product_name": "veritatis",
"product_price": "$30",
"discounted_price": "$27",
"discount": "$3",
"product_description": "Esse cupiditate eaque qui laboriosam quis id."
}
}
Received response:
Request failed with error:
Update Product Details
requires authentication
This endpoint is used to update a product's details.
Example request:
curl --request PUT \
"https://rest.iankumu.com/api/v1/products/17" \
--header "Authorization: Bearer <token>" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data "{
\"name\": \"Laptop\",
\"price\": 199,
\"description\": \"Non aperiam quia consequatur a facere sapiente.\"
}"
const url = new URL(
"https://rest.iankumu.com/api/v1/products/17"
);
const headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json",
"Accept": "application/json",
};
let body = {
"name": "Laptop",
"price": 199,
"description": "Non aperiam quia consequatur a facere sapiente."
};
fetch(url, {
method: "PUT",
headers,
body: JSON.stringify(body),
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$response = $client->put(
'https://rest.iankumu.com/api/v1/products/17',
[
'headers' => [
'Authorization' => 'Bearer <token>',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],
'json' => [
'name' => 'Laptop',
'price' => 199.0,
'description' => 'Non aperiam quia consequatur a facere sapiente.',
],
]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json
url = 'https://rest.iankumu.com/api/v1/products/17'
payload = {
"name": "Laptop",
"price": 199,
"description": "Non aperiam quia consequatur a facere sapiente."
}
headers = {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.request('PUT', url, headers=headers, json=payload)
response.json()
Example response (200, Update a Product):
{
"data": {
"id": 2,
"product_name": "veritatis",
"product_price": "$30",
"discounted_price": "$27",
"discount": "$3",
"product_description": "Esse cupiditate eaque qui laboriosam quis id."
}
}
Received response:
Request failed with error:
Delete a Product
requires authentication
This endpoint is used to delete a product from the database.
Example request:
curl --request DELETE \
"https://rest.iankumu.com/api/v1/products/12" \
--header "Authorization: Bearer <token>" \
--header "Content-Type: application/json" \
--header "Accept: application/json"
const url = new URL(
"https://rest.iankumu.com/api/v1/products/12"
);
const headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json",
"Accept": "application/json",
};
fetch(url, {
method: "DELETE",
headers,
}).then(response => response.json());
$client = new \GuzzleHttp\Client();
$response = $client->delete(
'https://rest.iankumu.com/api/v1/products/12',
[
'headers' => [
'Authorization' => 'Bearer <token>',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],
]
);
$body = $response->getBody();
print_r(json_decode((string) $body));
import requests
import json
url = 'https://rest.iankumu.com/api/v1/products/12'
headers = {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.request('DELETE', url, headers=headers)
response.json()
Example response (204, Delete a Product):
[Empty response]
Received response:
Request failed with error: