Welcome to the API documentation. Here you will find all the information you need to work with our API.
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);
{
"message": "User created successfully"
}
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);
{
"message": "Login successful",
"token": "YOUR_TOKEN"
}
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);
{
"title": "Post Title",
"body": "Post Body",
"user_id": 2,
"created_at": "2024-10-13 17:25:48",
"post_id": 6
}
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);
[
{
"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 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);
{
"message": "Logged out successfully"
}
To authenticate with the API, include your API key in the header:
Authorization: Bearer YOUR_TOKEN
Common error responses:
{
"error": "Resource not found"
}
{
"error": "Internal server error"
}