Skip to content
Advertisement

Suggestions on REST API & Software Architecture Style [closed]

First of all i am student, so i need to know how compounds Interact with each other, Maybe next time in the future i will do it with a framework, but first thing I need to do is knowing how to build the software form scratch.


My project will be web and mobile application so I decided to create a rest api for both… I will implement my project in Native PHP.

  • What is the best practice for software architecture style? but I don’t know what is the best practice software architecture for my rest api Multitiered(mvc, mvp, Or even something else like (model view controller data access))

    my idea about Multitiered(model view controller data access)
class Controller
{
    public $view;
    public $model;
    public $dataAccess;

    public function __construct()
    {
        $this->view = new View();
        $this->model = new Model();
        $this->dataAccess = new DataAccess();
    }
}
class UserController extends Controller
{
    public function __construct()
    {
        $this->model->tableName = "users";
    }

    public function get($id)
    {
        if($id) 
        {
            $this->model->data = $this->dataAccess->selectById($this->model->tableName, $id);
            $this->view->render($this->model->data);
        }
        else
        {
            $this->view->renderError();
        }
        
    }
}
class Application 
{
    private function __construct()
    {}
    
    public static function run() 
    {
        $router = new Router();
        $router->get("/users/([0-9]+)", array("UserController", "get"));
        $router->run();
    }
}


  • What about the file structure ?
    app/
    The app directory contains our rest-api components like controllers, views, models, data access.
    core/
    The directory contains the Router class and the basic classes
    Bootstrap/
    The directory contains the application.php file which bootstraps the framework by run function and autoload.php file which automatically loading PHP files.
    storage/
    logs, file caches, and user-generated files.

  • What about authentication and authorization?

    Will I need an extra layer for my architecture, model-view-controller-data access-(middleware or router)

    How will the rest api interact with other layers? For example, does the (middleware or router) layer interact with the controller then controller interact with data access layer for every authentication and authorization process


I will attach a simple implementation of the current phase to review my thoughts.

https://github.com/mahmoudahmedd/i-am-asking-for-feedback

Any other comments I would be grateful, Finally thanks.

Advertisement

Answer

great solution: learn on base applications of top frameworks.

  • Class Model work with DataAccess inside model
  • Models must extends Model
  • Controllers contain ‘action…’ methods to wrap model methods: ‘actionGet’, ‘actionCreate’, ‘actionDelete’ and etc. Route: namespace/controller/action, for example: api/user/get call ControllerApiUser::actionGet().

For example: https://github.com/koseven/koseven/blob/devel/system/classes/KO7/Controller.php , https://github.com/koseven/koseven/blob/devel/system/classes/KO7/Controller/Template.php

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement