Giter Club home page Giter Club logo

lumen-blog's Introduction

Lumen micro-service for blog posts

Very simple micro service with even simpler token based authentication.

Setup

Easy peasy, simply run the following commands:

  • git clone repository url
  • composer install
  • artisan:migrate

.env file

Duplicate .env.example and edit the following line to the bottom of your freshly created .env file. This will be the api token your other applications use to gain access to your micro-service. You should have secured your micro-services within a VPC or similar WAF to protect against unauthorised calls, but this gives you just that extra bit of protection, should you really need it.

API_TOKEN=TOKEN_GOES_HERE

Available End Points

All end points require an api_token header, which is the same as the one you set in your .env file.

Get all posts

GET /posts/all

Requires the following header:

  • api_token the api token you added to your .env file (required)

Returns JSON

// Valid response 200
{
  'success': true,
  'data': [
    {
      'id': (int) // post id,
      'user_id': (int) // user id of post,
      'title': (string) // post title,
      'content': (string) // post content,
      'created_at': (string) // created time eg: 2017-03-24 11:47:12,
      'update_at': (string) // updated time eg: 2017-03-24 11:47:12
    }
  ]
}

// Invalid response {response code}
{
  'success': false,
  'data': {
    'message': (string),
  }
}

Get post

GET /posts/get/{id}

Accepts the following parameters:

  • {id} being the id of the post you are requesting (required).

Accepts the following header:

  • api_token the api token you added to your .env file (required)

Returns JSON

// Valid response 200
{
  'success': true,
  'data': {
    'id': (int) // post id,
    'user_id': (int) // user id of post,
    'title': (string) // post title,
    'content': (string) // post content,
    'created_at': (string) // created time eg: 2017-03-24 11:47:12,
    'update_at': (string) // updated time eg: 2017-03-24 11:47:12
  }
}

// Invalid response {response code}
{
  'success': false,
  'data': {
    'message': (string),
  }
}

Insert post

PUT /posts/{api_token}/insert

Accepts the following parameters:

  • user_id (int) id of user that owns post (required)
  • title (string) post title (required)
  • content (string) post content (required)

Accepts the following header:

  • api_token the api token you added to your .env file (required)

Returns JSON

// Valid response 200
{
  'success': true,
  'data': {
    'id': (int) // post id,
    'user_id': (int) // user id of post,
    'title': (string) // post title,
    'content': (string) // post content,
    'created_at': (string) // created time eg: 2017-03-24 11:47:12,
    'update_at': (string) // updated time eg: 2017-03-24 11:47:12
  }
}

// Invalid response {response code}
{
  'success': false,
  'data': {
    'message': (string),
  }
}

Delete post

DELETE /posts/{api_token}/delete

Accepts the following parameter:

  • id (int) id of post you wish to delete (required)

Accepts the following header:

  • api_token the api token you added to your .env file (required)

Returns JSON

// Valid response 200
{
  'success': true,
  'data': {
    'id': (int) //post id
  }
}

// Invalid response {response code}
{
  'success': false,
  'data': {
    'message': (string),
  }
}

Update post

PUT /posts/{api_token}/update

Accepts the following parameters:

  • id (int) id of post to update (required)
  • user_id (int) id of user that owns post
  • title (string) post title
  • content (string) post content

Accepts the following header:

  • api_token the api token you added to your .env file (required)

Returns JSON

// Valid response 200
{
  'success': true,
  'data': {
    'id': (int),
    'user_id': (int),
    'title': (string),
    'content': (string),
    'created_at': (string),
    'update_at': (string)
  }
}

// Invalid response {response code}
{
  'success': false,
  'data': {
    'message': (string),
  }
}

Unit testing

Easy, just run the command phpunit from the root directory, composer should install this for you.

Left to do

  • Get posts by user id
  • Bulk update / edit / insert / get
  • Validation and better error responses
  • Better managment of tokens

lumen-blog's People

Contributors

adamgoose avatar barryvdh avatar coolbung avatar davesouthey avatar gaomd avatar grahamcampbell avatar heruputra avatar howlowck avatar jleft avatar joecohens avatar jrean avatar krienow avatar laurencei avatar martinssipenko avatar mdavis1982 avatar mhanson01 avatar michaeljhopkins avatar mul14 avatar nemanjakrstic avatar ntzm avatar pektop avatar roberto-aguilar avatar rohmanhm avatar sadika9 avatar takuto-h avatar taylorotwell avatar tillkruss avatar tongtastic avatar verheesj avatar zainulsaifulah avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.