1

I am creating the REST API using codeigniter. I downloaded this library and installed in my application. It works great! https://github.com/chriskacerguis/codeigniter-restserver

But I have an doubt. As per this library. I have 4 functoins

  1. GET
  2. POST
  3. PUT
  4. DELETE

I understand the functionality of each POST method but what I concern is how to write the validation and other things in the REST API.

Example: I have created the controller User.php

class User extends REST_Controller {
 public function __construct() 
 {
 parent::__construct(); 
 }
 // Get multile / individual users records and perform search also.
 public function index_get()
 { 
 $this->response('get / search users', REST_Controller::HTTP_OK);
 }
 // User Registration / Login
 public function index_post()
 { 
 echo 'create';
 }
 // User Information Update
 public function index_put()
 {
 echo 'update';
 }
 // User Delete
 public function index_delete()
 {
 echo 'delete';
 } 
}

I tested in postman post method works fine.

Here is my question. I have the following functionality for user.

  1. Register
  2. Login
  3. Forgot Password
  4. Change Password
  5. Update Profile

I think except Register other functions are posted with PUT method? In the PUT / POST method do I have to write all validations and database operation buy identity the post method variable using action likes register, login, forgot-password etc.,

In admin I want to get active or inactive users, find by email or name. this kind of operations where we have to write?

Thanks to all.

asked Jun 16, 2019 at 8:53

1 Answer 1

1

You can do all the basic validation on client-side, and if you need something to validate on server-side from the database you can manage the same in rest API.

  1. Register - this should be done on client-side
  2. Login - This can be done at server side by reading post parameter and validating same from the database.
  3. Change Password - Here again, password policy can be validated and client-side and other validation like do no use same password can be managed at server side
  4. Update Profile - Client-side validation

For writing server-side validation

class User extends REST_Controller {
 public function __construct() 
 {
 parent::__construct(); 
 }// User Registration / Login
 public function index_post()
 { 
 $username = $this->input->post('username');
 $password = $this->security->xss_clean($this->input->post("password"));
 $message = $this->Login_model->check_login($username,$password);
 $this->response($message);
 }
}
Glorfindel
3,1676 gold badges28 silver badges34 bronze badges
answered Aug 8, 2019 at 5:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.