Skip to content

codehunter12345/laravel-api-blog

Repository files navigation

A simple Blog Api implemented with Laravel 5.0

This Repo is Only For my Resume!!

Features

  • using (webpatser/laravel-uuid) to create uuid for posts table
  • using Html Purifier (mews/purifier) to sanitize and clean input data (security and xss)
  • All input and output data are Json.

Api Routes

  • Route: api/v1/blog/ => Responses all posts as json
  • Route: api/v1/blog/show => Outputs One or Array of posts for given uuid's
  • Route: api/v1/blog/add => Inserts One or Array of given Posts into database
  • Route: api/v1/blog/update => Updates One or Array of Posts
  • Route: api/v1/blog/delete => Deletes One or Array of given uuids from database

Installation

  • Clone or Download Repo
  • To install dependencies: composer install
  • To create tables : php artisan migrate
  • To seed tables : php artisan db:seed

Usage

Route: api/v1/blog :

With GET request simply type the url in browser and all posts are returned as Json. You can set limit parameter to url for number of records returned from api. You can move between pages by setting page parameter in Url

Route: api/v1/blog/show

POST uuids in Json format to this route and it will return all the posts with the provided uuids.

The Json format should be like following:

 {
     "uuids":
          [
            "2019aa37-1aae-40d3-9b7a-c8c77bc56bef",
            "3a1b86b6-aea9-44fe-9ffd-a9e9add0bf95"
         ]

}

Route: api/v1/blog/add

POST (Data that you want to save to database) to this route as Json and it will insert these data to database.

The Json format should be like following:

 {
     "data":
         [
            {  
               "title":"title1",
               "body": "post 1 body!",
               "slug": "slug"
            },
            {   
               "title":"title2",
               "body": "post 2 body!",
               "slug": "slug2"
            }
        ]
    }

Route: api/v1/blog/update

In order to update some posts you should POST a Json data that includes uuid and other attributes for posts table.

The Json format should be like this:

 {
     "data":
         [
            {  

               "id":"1050fee5-fc3c-4ec9-9e4f-69a3adf801bb"
               "title":"title1",
               "body": "post 1 body!",
               "slug": "slug"
            },
            { 

               "id":"255e7eeb-142e-4777-b54c-503be090820e" 
               "title":"title2",
               "body": "post 2 body!",
               "slug": "slug2"
            }
        ]
    }

Route: api/v1/blog/delete

POST uuids Json to this route and all the uuids provided will be deleted from database.

The Json File should be like following:


 {
     "uuids":
         [
            "2011e883-3ac7-41c9-afdc-facd3fc879ba",
            "27bd977d-f3da-4fb6-b862-815d44233f48"  
         ]

}

License

MIT License.

About

A simple Blog Api for Laravel 5. using Uuid for id field.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages