PHPackages                             anshu-krishna/api-framework - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. anshu-krishna/api-framework

ActiveLibrary[API Development](/categories/api)

anshu-krishna/api-framework
===========================

API Framework

11.5.4(1y ago)0100MITJavaScriptPHP &gt;=8.1

Since Sep 16Pushed 1y ago2 watchersCompare

[ Source](https://github.com/anshu-krishna/PHP-API-Framework)[ Packagist](https://packagist.org/packages/anshu-krishna/api-framework)[ RSS](/packages/anshu-krishna-api-framework/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (2)Versions (17)Used By (0)

API Framework
=============

[](#api-framework)

This is a simple API framework that can be used to create APIs.

Installation:
-------------

[](#installation)

```
composer require anshu-krishna/api-framework
```

Quick Start Guide (using the provided sample code as example):
--------------------------------------------------------------

[](#quick-start-guide-using-the-provided-sample-code-as-example)

Let's create a simple API server and on the way learn how to use this framework.

See the [sample](./sample/) directory for the full sample server code.

In this example we will assume that this server is running at  .

### Files List:

[](#files-list)

```
codebase-root/
├─ api-funcs-base/
│  ├─ @all.php
│  ├─ @index.php
│  ├─ Ping.php
│  ├─ Example/
│  │  ├─ @all.php
│  │  ├─ @index.php
│  │  ├─ Adder.php
│  │  ├─ CamelCase/
│  │  │  ├─ @index.php
│  │  │  ├─ Hello.php
├─ public/
│  ├─ .htaccess
│  ├─ index.php

```

#### Explanation of the listed files:

[](#explanation-of-the-listed-files)

- `codebase-root/` This is the root directory of the codebase. (Choose any directory).
- `codebase-root/api-funcs-base/` This is the directory where all the API definitions are stored. (Directory name does not need to be `api-funcs-base`. It can be anything.)

    - `@all.php` \[Optional\] This file is executed before all the APIs in this directory **and its subdirectories**.
    - `@index.php` \[Optional\] This file defines the API available at
    - `Ping.php` This file defines the API available at
    - `Example/` This directory contains all APIs grouped under 'example' API.

        - `@all.php` \[Optional\] This file is executed before all the APIs in this directory **and its subdirectories**.
        - `@index.php` \[Optional\] This file defines the API available at
        - `Adder.php` This file defines the API available at
        - `CamelCase/` This directory contains all APIs grouped under 'example.camel\_case' API.

            - `@index.php` \[Optional\] This file defines the API available at [https://api.sample.dev/example.camel\_case](https://api.sample.dev/example.camel_case)
            - `Hello.php` This file defines the API available at [https://api.sample.dev/example.camel\_case.hello](https://api.sample.dev/example.camel_case.hello)
- `codebase-root/public/` This is the public directory where the server is running. (i.e.  must point to this directory.) *Directory name does not need to be `public`. It can be anything.*

    - `.htaccess` This file is used to rewrite the URLs to the API framework.
    - `index.php` This file is the entry point of the server.

#### Sample code for some of the files (with explanations/comments):

[](#sample-code-for-some-of-the-files-with-explanationscomments)

```
