Skip to content

A demo blog API written in Laravel for demo purposes of containerization, CI/CD, and microservices implementation.

License

Notifications You must be signed in to change notification settings

mfandrade/apiblog

Repository files navigation

apiblog

apiblog - a simple blog API for demo purposes.

Deployed at AWS

This is a repository for a sample application that implements the essence of a blog in API format.

The main purpose here is it can be used as a demo app for DevOps, CI/CD practices, automation and hosting on cloud servers.

KEYWORDS: api, laravel, php, mvc, sqlite, mysql, devops, ci, ci/cd, gitlab-ci, aws, amazon, cloud, cloudcomputing, terraform, cloudformation, microservices

tl;dr

$ git clone [email protected]:mfandrade/apiblog.git
$ cd apiblog
$ make run

Tell me a bit more

The API consists in a MVC application (well, tecnically without views) written in Laravel 9. It represents the very core essence of a blog with only two models: Post and Comment. A post can have many comments but a comment belong to only one post.

There are a couple of sample data populated to those models via migrations. We can view those data acessing this API via REST.

Requirements

Project structure

apiblog/
├── src/                     - root dir of the Laravel application
│   ├── .env.local           - file with env vars for local execution
│   └── .env.production      - file with env vars for production execution
├── files /                  - miscelaneous files mainly used in Dockerfile
│   ├── cloudformation.yaml  - one-tier infrastructure designed to run on AWS
│   └── laravel.conf         - simple vhost configuration to serve the app in Apache2
├── Dockerfile               - Dockerfile to containerize the Laravel application
├── Makefile                 - swiss-knife for running, testing and deploying the app
├── docker-compose.yaml      - docker-compose file for local test in two-tier mode
├── .github/workflows/       - artifacts for CI/CD via GitHub Actions
└── .gitlab-ci.yaml          - artifact for CI/CD via Gitlab-CI

How to test this API?

1. Bring it on

2. Check it's up and running

3. Run some HTTP requests against the endpoints

What? How? Where?
GET status it's working curl -sL $APP_URL/api -
GET all posts curl -sL $APP_URL/api/posts PostsController@index
GET first post curl -sL $APP_URL/api/posts/1 PostsController@show
POST create a new post curl -sL -X POST -d "{title='Title',body='Body'}" -H "Content-Type: application/json" $APP_URL/api/posts PostsController@store
PUT update a post curl -sL -X PUT -d "{title='New Title'}" -H "Content-Type: application/json" $APP_URL/api/posts/3 PostsController@update
DELETE a post curl -sL -X DELETE $APP_URL/api/posts/3 PostsController@destroy
GET post from a comment curl -sL $APP_URL/api/comments/1/post CommentsController@post
GET comments from a post curl -sL $APP_URL/api/posts/2/comments PostsController@comments

Marcelo F Andrade | CONTRIBUTING | LICENSE

About

A demo blog API written in Laravel for demo purposes of containerization, CI/CD, and microservices implementation.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages