REST is usefull scaffold for making rest APIs using php. It is simple, fast and lightweight.
- Installation
- Url Structure
- Naming conventions
- Database
- Cache
- Helpers
- Validations
- Mails
- Push Notifications
- Async HTTP requests
$ git clone https://github.com/jagroop/rest.git
$ cd rest
$ composer install
http://localhost/rest/web/class/method/param_1/param_2/..../param_n
- All files in app folder should be in "title case", for example:
App.php
,Users.php
,UserPosts.php
etc.
Laravel 5 Helpers for Non-Laravel Projects
New Validation Rules:
//unique,table_name or if column name is different in db unique,table_name:col_name
$rules = array('email' => 'required|valid_email|unique,users');
//exist,table_name or exist,table_name:col_name
$rules = array('user_id' => 'required|exist,users:id');
$request = request(['name', 'email']);
$this->validate($request, $rules);
//Now you can insert your data in DB
$this->db->table('users')->insert($request);
use App\Artisan\Mail;
$user = $this->db->table('users')->where('id',1)->get();
//templates are in resources/email folder
$mail = Mail::send('template_name', compact('user'))
->to('example@gmail.com', 'John Doe')
->subject('This is a test subject')
->deliver();
use App\Artisan\Notification;
$user = $this->db->table('users')->where('id',1)->get();
$payload = [
'message' => 'Test notification.',
'badge' => 2
];
Notification::send($user, $payload);
async('sendNewOfferEmail', ['offer_id' => 123]);
//Async requests target functions are defined in app/Async.php
//example:
class Async {
public function sendNewOfferEmail(){
$offerId = (int) request('offer_id');
//...
}
}