# Leaf API

Leaf API is a lightweight and minimal MVC wrapper leaf PHP framework that provides a more scalable and powerful setup for creating APIs quickly and efficiently. Leaf API is also heavily inspired by Ruby on Rails, Laravel and Slim, it provides you the best of these packages and avoids the "not so goods" 😁

v3.0 packs in a bunch of fresh functionality, and also features added in v3 (opens new window) of the core Leaf package. You can view all these changes here.

# Why Leaf API?

There are a variety of tools and frameworks available to you when building an API, however, we believe Leaf + MVC is the best choice for building modern, API based solutions for the reasons below.

# Shallow learning curve

Whether you are new to PHP or have prior experience with the language, Leaf API helps you fit right in. All you need to get started with Leaf API is basic PHP knowledge and a little familiarity with MVC concepts. You can learn leaf as you build.

# Lightweight

If you have experience with other MVC frameworks like Laravel, you would notice how simple and straightforward Leaf API is compared those which need you to learn a whole bunch of their framework specific stuff. Leaf is light and so is Leaf API.

# Powerful

Leaf API packs a ton of powerful tools which speed up your development process by folds. You have simple tools and modules like authentication (opens new window), commands with aloe (opens new window), MVC tools with MVC core (opens new window) and a ton of other modules (opens new window).

# Installation

You can quickly create a Leaf API project with the leaf cli (opens new window):

leaf create <project-name> --api --v3
1

or with composer (opens new window).

composer create-project leafs/api <project-name>
1

# Directory Structure

This will create a new Leaf API project named <project-name>. Inside the new directory, you should have a structure like this.

Note

The directory structure has had a refresh. We normalized the folder cases to lowercase. Note that this only applies to the default Leaf API folders. Custom folders will have to follow the class structure as done in earlier versions.

C:.
├───app
│   ├───console
│   ├───controllers
│   │   └───Auth
│   ├───database
│   │   ├───factories
│   │   ├───migrations
│   │   └───seeds
│   ├───helpers
│   ├───models
│   ├───routes
│   └───views
│       ├───components
│       └───pages
│           └───errors
├───config
│   └───command
├───public
│   └───assets
├───storage
│   ├───app
│   │   └───public
│   ├───framework
│   │   └───views
│   └───logs
└───vendor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  • app: This is where you will mostly be working. It houses all your controllers, command and db files.
  • config: This holds all your configuration files.
  • lib: You can place your libraries and piece files which you need for your app.
  • public: This holds the entry point to your app, as well as static assets
  • storage: Storage for your files, images, text, databases...
  • vendor: This holds all your dependencies and installed files.

Besides the folders already created for you, Leaf API has also normalized a set of folders which you can use in your apps.

  • app/http
  • app/jobs
  • app/utils
  • app/workers
  • app/services

You can manually add these as you see fit.

# Running your Leaf API project

In the project root, you can open up your console tool and type in

php leaf serve
1

This will start the php web server and load your project at http://localhost:5500 by default.

Note

This php leaf command is powered by Leaf MVC's (opens new window) Aloe CLI tool (opens new window). You should note that Aloe CLI tool (opens new window) is different from the Leaf CLI (opens new window). Aloe is more of a scaffold tool for Leaf MVC and Leaf API, but Leaf CLI helps you generally create and manage your Leaf applications. Leaf CLI might have some shared features with Aloe, but it is a higher level tool.