Skip to content

Simple API application used to learn the more in-depth Laravel techniques.

License

Notifications You must be signed in to change notification settings

JoeBocock/knockt

Repository files navigation


Twitter License Issues Elementary

Table of contents

About Knockt

Knockt is an example Laravel API implementation.

Developed originally to teach junior PHP developers how to utilise Laravel, it's now a lightweight showcase of common features people can often see as ✨magic✨.

As this project continues to grow and be worked on I will update this README with endpoint information etc however if I find that it gets too cluttered, I may move it off to another more dedicated site.

Interested in some front end concept designs? Check out my login form concept for this project on CodePen!


Development Notes

Using Microsoft API Best Practices and common web design methods, this is designed to be as standard as possible with very little deviation. This defines our base response structure, HTTP codes and request handling practices.


Getting Setup

Prerequisites

Here's a quick fire list of steps to get started with the project locally. Please note this assumes that you have a basic understanding of development with PHP and have at least very basic knowledge of composer.

  1. Clone the repository.
  2. Run composer install within your working directory.
  3. Run cp .env.example .env within your working directory.
  4. Run php artisan key:generate within your working directory.

Required Reading?!

If any of the above is confusing or you're not to sure what each command is doing, I'll provide a very simple explanation below along with a link to read more on the subject.

  1. Here we are cloning the repository with a source control tool called git. If you're not sure what git it, I'd suggest reading up on that before trying to tackle this project. Here's the offical git documenation, they have some great videos explaining the concept.
  2. Composer is a PHP dependacy manager that handles a lot of tedious and often error prone work. Here's the offical Composer documenation.
  3. Here we are simply copying an existing example configuration file. .ENV files often contain sensitive information for your application and as such, shouldn't be commited to version control. Here's the github page for phpdotenv.
  4. Finally, we are using a local tool called artisan to generate an application key. This is a Laravel specific step that allows our application to have a unique encryption key. More can be found on this subject on the Laravel Documentation.

Please Note! The default .ENV file provided with Knockt assumes you are going to use docker as your development environment.


Local Environment

Thanks to Laravel and it's wide range of local tooling, we have quite a few options to get up and running.

Our application currently requires PHP 8.1 and MySQL 8 as it's core building blocks of infastructure. If you have the knowledge to locally configure Apache or Nginx and prefer to work that way, go ahead! Please note I won't provide any support for this local tooling however.

The main three development tools provided by Laravel out of the box are Sail, Valet and Homestead. But what are they?

New with Laravel 8, along came Sail! Laravel Sail is a nice docker wrapper configured to work perfectly with your Laravel projects out of the box. It is by far the easiest way to get up and running with a Laravel project and requires a user to have little to no experience with Docker itself (although I'd recommend reading into it as it's a very powerful tool). The only prerequisite here is having Docker itself installed on your machine and running.

Assuming you have Docker installed and running, simply run ./vendor/bin/sail up within your working directory and visit http://knockt.test/. You should recieve a very simple JSON response of 404 Not Found. Don't panic, this means it's working! For more in-depth knowledge on working with Sail and Docker see here and here.

As mentioned, Laravel also offers Valet and Homestead. Both of which require further configuration that is beyond this README. You can find the documentation for Valet here and Homestead here.

Side Note: If you happen to be on Linux and want to use Valet, fear not! cpriego has created Valet Linux.


Endpoint Documentation

Posts

Method Path Description
GET /api/posts Lists all Posts
POST /api/posts Store a new Post
GET /api/posts/{id} Retrieve a specific Post
PUT /api/posts/{id} Update an existing Post
DELETE /api/posts/{id} Remove an existing Post

Note: There's a Postman Collection in the repository if that works for you. Know that you may need to setup the {{URL}} environment variable, which is usually http://localhost/api.