Get started
API Endpoints ------------- Blog Posts ==========http://localhost/swifty/api/post http://localhost/swifty/api/post/read.php http://localhost/swifty/api/post/single.php?id=post_id http://localhost/swifty/api/post/create.php http://localhost/swifty/api/post/update.php http://localhost/swifty/api/post/delete.php
Categories ==========http://localhost/swifty/api/category http://localhost/swifty/api/category/read.php http://localhost/swifty/api/post/single.php?id=category_id http://localhost/swifty/api/category/create.php http://localhost/swifty/api/category/update.php http://localhost/swifty/api/category/delete.php
Swifty — is an open source REST API created using Core PHP and OOP. This is basically my very first REST API project. It's pretty SIMPLE, MINIMAL & POWERFUL!
This is an Open Source API, so to use this API you don't need API key. If you confront any error, please contact me at GitHub
To get started, if you downloaded this repository from GitHub then
please import
swifty.sql
file to your
MySQL Database. It includes required Table Schemas and some dump
data
While you're trying to
Create
,
Update
, or
Delete
through API, make
sure your provided data are in JSON format. Because
header
only accepts
Content-Type: application/json
in these requests.
Get Blog Posts
To get blog posts you need to make a
GET
call to the following
url :
http://localhost/switfy/api/post/read.php
Get Blog Post Result Format Example :
[
{
"id": "1",
"category_id": "5",
"category_name": "Trending",
"title": "Post Title",
"body": "The Blog Post",
"author": "Author Name",
"created_at": "2022-06-29 16:56:26"
} ...
]
This will provide all the blog posts. So, you don't have to pass any QUERY PARAMETERS
Get a Single Blog Post
To get blog a specific post you need to make a
GET
call to the following
url :
http://localhost/switfy/api/post/single.php?id=post_id
The URL should look like:http://localhost/switfy/api/post/single.php?id=1
Result if any post exists: [ { "id": "1", "category_id": "5", "category_name": "Trending", "title": "Post Title", "body": "The Blog Post", "author": "Author Name", "created_at": "2022-06-29 16:56:26" } ]
Just pass the post id to get the specific post from API
Create a Blog Post
To create a new blog post you need to make a
POST
request to the
following url :
http://localhost/switfy/api/post/create.php
Create Blog Post JSON format Example :
{
"category_id": int,
"title": "string",
"body": "string",
"author": "string",
}
On Success, Response Message Will Be:
{
"message": "Post Created Successfully"
}
QUERY PARAMETERS
Field | Type | Description |
---|---|---|
category_id | Integer | Post Category |
title | String | Your post title |
body | String | Your post content |
author | String | Post author name |
Update a Blog Post
To update a new blog post you need to make a
PUT
request to the
following url :
http://localhost/switfy/api/post/update.php
Update Blog Post JSON format Example :
{
"id": 0,
"category_id": int,
"title": "string",
"body": "string",
"author": "string",
}
On Success, The Response Will Be:
{
"message": "Post Updated Successfully"
}
QUERY PARAMETERS
Field | Type | Description |
---|---|---|
id | Integer | Existing Post Id |
category_id | Integer | Post Category |
title | String | Your post title |
body | String | Your post content |
author | String | Post author name |
Delete a Blog Post
To delte a blog post you need to make a DELETE request to the
following url :
http://localhost/switfy/api/post/delete.php
Delete Blog Post JSON format Example :
{
"id": 0
}
Success Response Will Be
{
"message": "✅ Category Deleted!"
}
QUERY PARAMETERS
Field | Type | Description |
---|---|---|
id | Integer | Just provide the Post Id to be deleted |