rest - Laravel - What is exactly a RESTful API? -


i'm working on school project, , project name is: ...using web restful api...

so, decided write android application client-side, , server-side laravel framework (version 5).

what understand when hear rest api is: get, put, delete, edit, update, index.

this why have created class named apicontroller project contains it's methods communicate "exterior".

an example of how think user registration should work:

routes.php  route::post('/register', array('uses' => 'apicontroller@postregisteruser', 'as' => 'postregisteruser')); 

and apicontroller:

class apicontroller extends controller {      public function postregisteruser() {         $validator = validator::make(input::all(), array(             'email' => 'required|email|unique:users,email',             'uuid'  => 'required|unique:users,uuid',             'name'  => 'required|min:6'         ));          if ($validator->fails()) {             return utils::buildjsonresponse(false, array('invalid parameters', $validator->messages()), null);         }          $password = utils::generaterandomstring(6);          $result = array(             'email'     => input::get('email'),             'password'  => $password,             'uuid'      => input::get('uuid')         );          $user = new user();         $user->email = input::get('email');         $user->password = hash::make($password);         $user->name = input::get('name');          $phone_number = input::get('phone_number');         if ($phone_number != null) {             $user->phone_number = $phone_number;         }          if (!$user->save()) {             return utils::buildjsonresponse(false, array('an error occurred'), null);         }          return $response = utils::buildjsonresponse(true, null, $result);     }  } 

and helper class:

... public static function buildjsonresponse($success, $errors, $data) {         $result = array();          $result['success']  = $success;         $result['error']    = $errors;         $result['data']     = $data;          return response::json($result, 200, array(), json_pretty_print);     }  ... 

is right approach?

is how rest api should work?

i'm confused, because have seen other examples on internet, people said model class (in case user.php) should contain rest methods.

also, have found example: http://laravel.com/docs/5.0/controllers#restful-resource-controllers

if @ table, see controller class "photocontroller" comes default rest methods. of abstraction? should implement, methods creating, editing, deleting, etc.?


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -