You’re browsing the documentation for v3.x.

  Click here  for earlier leaf api versions.

# Leaf API

Leaf API is a lightweight and minimal MVC wrapper leaf PHP framework that provides a more scalable and powerful setup for creating web apps and 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.

Also, the lightweight core framework is not always suitable for every use case, which is another reason a scalable setup in the form of Leaf API has been created.

# Why Leaf API?

There are a variety of tools and frameworks available to you when building a web application. However, we believe Leaf + MVC is the best choice for building modern, full-stack web applications.

# 📚 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 had 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 things. 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/mvc <project-name> v3.x-dev
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.

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.