All Projects → rocboss → Batio

rocboss / Batio

Licence: mit
A fast and extensible micro-framework for PHP to build RESTful API.

Projects that are alternatives of or similar to Batio

Standards.rest
A collection of standards, specifications, etc. for HTTP API development.
Stars: ✭ 58 (-33.33%)
Mutual labels:  restful-api
Gorse
An open source recommender system service written in Go
Stars: ✭ 1,148 (+1219.54%)
Mutual labels:  restful-api
Parvula
An extremely simple & flexible CMS generated from flat files with a complete RESTful API —
Stars: ✭ 76 (-12.64%)
Mutual labels:  restful-api
Restfeel
RESTFeel: 一个企业级的API管理&测试平台。RESTFeel帮助你设计、开发、测试您的API。
Stars: ✭ 59 (-32.18%)
Mutual labels:  restful-api
Spacex Api
🚀 Open Source REST API for SpaceX launch, rocket, core, capsule, starlink, launchpad, and landing pad data.
Stars: ✭ 8,973 (+10213.79%)
Mutual labels:  restful-api
Jokeapi
A REST API that serves uniformly and well formatted jokes in JSON, XML, YAML or plain text format that also offers a great variety of filtering methods
Stars: ✭ 71 (-18.39%)
Mutual labels:  restful-api
Api Strategy
Equinor API Strategy
Stars: ✭ 56 (-35.63%)
Mutual labels:  restful-api
Evolutility Server Node
Model-driven REST or GraphQL backend for CRUD and more, written in Javascript, using Node.js, Express, and PostgreSQL.
Stars: ✭ 84 (-3.45%)
Mutual labels:  restful-api
Laravel Restful Api Starter
Build a RESTful API with Laravel and MongoDB
Stars: ✭ 66 (-24.14%)
Mutual labels:  restful-api
Restfm
RESTful web services for FileMaker server.
Stars: ✭ 76 (-12.64%)
Mutual labels:  restful-api
Web Api
RESTful web server for Minecraft Sponge including an admin panel
Stars: ✭ 60 (-31.03%)
Mutual labels:  restful-api
Beauty
A microframework based on mymysql,net/http,jwt-go and mux.
Stars: ✭ 61 (-29.89%)
Mutual labels:  restful-api
Lumen Api Oauth
A RESTful API based on Lumen micro-framework with OAuth2.
Stars: ✭ 73 (-16.09%)
Mutual labels:  restful-api
Openapi Generator
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
Stars: ✭ 10,634 (+12122.99%)
Mutual labels:  restful-api
Aztro
The Astrology API 💫 Get daily horoscope!
Stars: ✭ 78 (-10.34%)
Mutual labels:  restful-api
Deno Api Starter Oak
Deno RESTful API project starter for oak framework
Stars: ✭ 57 (-34.48%)
Mutual labels:  restful-api
Springboot security restful api
SpringBoot + SpringSecurity + RESTful API --- Maven Project Demo
Stars: ✭ 68 (-21.84%)
Mutual labels:  restful-api
Python Ilorest Library Old
Python library for iLO RESTful API
Stars: ✭ 85 (-2.3%)
Mutual labels:  restful-api
Jayme
Abstraction layer that eases RESTful interconnections in Swift
Stars: ✭ 79 (-9.2%)
Mutual labels:  restful-api
Graceful
Elegant Python REST toolkit built on top of falcon
Stars: ✭ 73 (-16.09%)
Mutual labels:  restful-api

Batio

Build Status Branch master Latest Stable Version Latest Unstable Version License

English | 简体中文

A fast and extensible micro-framework for PHP to build RESTful API.

1. Install

// (Recommend) If you’re using Composer, you can run the following command:
composer create-project --prefer-dist rocboss/batio batio
// Or git clone
git clone https://github.com/rocboss/batio.git batio
cd batio

cp .env.example .env
// Edit .env file
vim .env

composer install
chmod -R 755 app/storage

php -S 127.0.0.1:8888 -t public

Enter http://127.0.0.1:8888 in the browser's address bar. If everything is correct, you can get the following return:

{
  "code": 0,
  "msg": "success",
  "data": "version: Batio 1.0.0"
}

Note: the initial installation needs to edit the related configuration information in the .env file under the project root, and you can also extend the other configuration in the file according to specific requirements.

2. Framework

2.1 Router

In app\config\routes.php, you can customize API routes.

route('GET /', ['api\HomeController', 'index']);

This is an ordinary route. When you visit the home page, you directly map to the api\HomeController controller, execute the following index method, and note that the type of controller method needs to be protected.

2.2 Middlewares

In app\config\app.php, you can customize Middleware for routes, such as authorization authentication, user roles control, etc.

// Middlewares
'middlewares' => [
    'auth' => AuthMiddleware::class,
],

Batio encapsulates a simple authentication model based on JWT, just call the auth() method after the routing of the authentication API.

route('GET /', ['api\HomeController', 'user'])->auth();

The example

// Fail
{
    "code": 401,
    "msg": "[401 Unauthorized]."
}

// Success
{
    "code": 0,
    "msg": "success",
    "data": {
        "uid": 1,
        "user_name": "Jack",
        "user_age": 18
    }
}

When you send a request, pass the X-Authorization of JWT value to the server in header.

// This method can be used to obtain JWT.
\Auth::getToken($uid);

2.3 Cache

if (app()->cache('data')->contains('foo')) {
    $unit = app()->cache('data')->fetch('foo');
} else {
    $bar = 'bar cache';
    app()->cache('data')->save('foo', $bar);
}

2.4 Log

$logger = app()->log()->debug('debug log');

2.5 Database & Models

$userModel = new UserModel();
$userModel->name = 'Jack';
$userModel->email = '[email protected]';
$userModel->avatar = 'https://foo.com/xxxxxx.png';
$userModel->password = password_hash("mypassword", PASSWORD_DEFAULT);
$userModel->save();

In app\models, model and service are stored, model is mainly dealing with database. The official recommended practice is that service calls model, controller calls service, so that the design makes the layering more reasonable, and the functional modules are decoupled to facilitate the business system.

Mainly depended on

lcobucci/jwt: 3.2.*
mikecao/flight: 1.3.*
aryelgois/medools: 5.0
catfan/medoo: 1.5.*
monolog/monolog: 1.23.*
doctrine/cache: 1.4.*
vlucas/phpdotenv: 2.0.*
predis/predis: 1.1.*
ruflin/elastica: 6.1.*
elasticsearch/elasticsearch: 6.0.*

Batio uses some excellent third party components, and you can get specific documents from their websites.

Authorization agreement

MIT Agreement

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].