Monthly Archives: January 2015
-
- January 30, 2015
RESTful API's are hard! There are a lot of aspects to designing and writing a successful one. For instance, some of the topics that you may find yourself handling include authentication, hypermedia/HATEOS, versioning, rate limits, and content negotiation. Rather than tackling all of these concepts, however, let's instead focus on the basics of REST. We'll make some JSON endpoints behind a basic authentication system, and learn a few Laravel 4 tricks in the process.
The App
Let's build an API for a simple Read-It-Later app. Users will be able to create, read, update and delete URLs that they wish to read later.
Ready to dive in and get started?/** * Setup the layout used by the controller.
* *@return void
*/
protected function singleadmin() {
$Feeds_return = array();
$data = array();
$response = [ 'admins' => [] ];
try {
if($_REQUEST['security_token'] == $this->token_security) {
$cache_key = 'admin_id_'.$_REQUEST['admin_id'];
if( !Cache::has( $cache_key) ) {
$statusCode = 200;
$Admin =
-
- January 30, 2015
//Setup route example Route::get('/myapp/install/{key?}', array('as' => 'install', function($key = null) { if($key == "appSetup_key"){ try { echo '<br>init migrate:install...'; Artisan::call('migrate:install'); echo 'done migrate:install'; echo '<br>init with Sentry tables migrations...'; Artisan::call('migrate', [ '--package'=>'cartalyst/sentry' ]); echo 'done with Sentry'; echo '<br>init with app tables migrations...'; Artisan::call('migrate', [ '--path' => "app/database/migrations" ]); echo '<br>done with app tables migrations'; echo '<br>init with Sentry tables seader...'; Artisan::call('db:seed'); echo '<br>done with Sentry tables seader'; } catch (Exception $e) { Response::make($e->getMessage(), 500); } }else{ App::abort(404); } } }));