API Documentation

Welcome to the API documentation. Here you will find all the information you need to work with our API.

API Endpoints

POST /api/v1/register

Sample Request with PHP
POST https://www.restapi.hello-sharma.com/api/register

$url    = 'https://www.restapi.hello-sharma.com/api/register';
$ch     = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Accept: application/json', 
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    "name"                  => "New User",
    "email"                 => "newuser@example.com",
    "password"              => "password",
    "password_confirmation" => "password"
]));
$response = curl_exec($ch);
if(curl_errno($ch)){
    echo 'cURL error: ' . curl_error($ch);
}
curl_close($ch);
Response:
{
    "message": "User created successfully"
}

POST /api/v1/login

Sample Request with PHP
POST https://www.restapi.hello-sharma.com/api/login
    
$url    = 'https://www.restapi.hello-sharma.com/api/login';
$ch     = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Accept: application/json', 
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    "email"     => "newuser@example.com"
    "password"  => "password",
]));
$response = curl_exec($ch);
if(curl_errno($ch)){
    echo 'cURL error: ' . curl_error($ch);
}
curl_close($ch);
Response:
{
    "message": "Login successful",
    "token": "YOUR_TOKEN"
}

POST /api/v1/post/create

Sample Request with PHP
POST https://www.restapi.hello-sharma.com/api/post/create

$url    = 'https://www.restapi.hello-sharma.com/api/post/create';
$ch     = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Accept: application/json', 
    'Authorization: Bearer YOUR_TOKEN',
]);    
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    "title"     => "post title"
    "body"      => "Post body",
]));
$response = curl_exec($ch);
if(curl_errno($ch)){
    echo 'cURL error: ' . curl_error($ch);
}
curl_close($ch);
Response:
{
    "title": "Post Title",
    "body": "Post Body",
    "user_id": 2,
    "created_at": "2024-10-13 17:25:48",
    "post_id": 6
}

GET /api/v1/post

Sample Request with PHP
GET https://www.restapi.hello-sharma.com/api/post

$url    = 'https://www.restapi.hello-sharma.com/api/post';
$ch     = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Accept: application/json', 
    'Authorization: Bearer YOUR_TOKEN',
]);    
$response = curl_exec($ch);
if(curl_errno($ch)){
    echo 'cURL error: ' . curl_error($ch);
}
curl_close($ch);
Response:
[
    {
        "post_id": 1,
        "title": "HELLO WORLD",
        "body": "THIS IS THE HELLO WORLD POST BODY",
        "user_id": 2,
        "created_at": 2024-10-12 17:25:48,
        "updated_at": null
    },
    {
        "post_id": 6,
        "title": "Post Title",
        "body": "Post Body",
        "user_id": 2,
        "created_at": "2024-10-13 17:25:48",
        "updated_at": null
    }
]

POST /api/v1/logout

Sample Request with PHP
POST https://www.restapi.hello-sharma.com/api/logout

$url    = 'https://www.restapi.hello-sharma.com/api/logout';
$ch     = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Accept: application/json', 
    'Authorization: Bearer YOUR_TOKEN',
]);    
curl_setopt($ch, CURLOPT_POST, true);
$response = curl_exec($ch);
if(curl_errno($ch)){
    echo 'cURL error: ' . curl_error($ch);
}
curl_close($ch);
Response:
{
    "message": "Logged out successfully"
}

Authentication

To authenticate with the API, include your API key in the header:

Header:
Authorization: Bearer YOUR_TOKEN

Errors

Common error responses:

404 Not Found:
{
    "error": "Resource not found"
}
500 Internal Server Error:
{
    "error": "Internal server error"
}