Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3277050
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:19:40+00:00 2026-05-17T19:19:40+00:00

I am developing an api layer for my application. I have designed a structure

  • 0

I am developing an api layer for my application. I have designed a structure and need some advice/feedback for it. You can find the basic implementation of the structure at the bottom.

Here are my requirements for the structure:

  • Response from API commands may need to be formatted in different formats (JSON,XML,etc.)
  • Some API commands may require authentication, some may not
  • Every API command should be open to extension via plugins (Notification on events, filtering of input/output paramters, etc.)

With these requirements in mind I have applied Decorator pattern to my API layer. I am not sure if I have designed the structure right and need to be sure about it.

The last item in requirements list is not covered in the implementation below because I am still trying to figure out how to do that.

What do you think? Am I on the right path?

<?php

// Interfaces
interface I_API_Command {}

// Abstract classes
abstract class A_API_Command implements I_API_Command
{
    abstract public function run();
}

abstract class A_Decorator_API_Command implements I_API_Command
{
    protected $_apiCommand;
    public function __construct(I_API_Command $apiCommand) {
        $this->_apiCommand = $apiCommand;
    }
    abstract public function run();
}

// Api command class
class APIC_Tasks_Get extends A_API_Command
{
    public function run() {
        // Returns tasks
    }
}

// Api command decorator classes
class APICD_Auth extends A_Decorator_API_Command
{
    public function run() {
        // Check authentication
        // If not authenticated: return error

        // If authenticated:
        return $this->_apiCommand->run()
    }
}

class APICD_JSON_Formatter extends A_Decorator_API_Command
{
    public function run() {
        return json_encode($this->_apiCommand->run());
    }
}

// Usage
$apiCommand = new APICD_JSON_Formatter(new APICD_Auth(new APIC_Tasks_Get()));
$apiCommand->run();

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:19:41+00:00Added an answer on May 17, 2026 at 7:19 pm

    In my opinion… i think that old-classic MVC would be enough..

    Response from API commands may need to be formatted in different
    formats (JSON,XML,etc.)

    The controller would read the request and change the view to output the information in the selected format. Or you could pass the request to the View and the view would change the output format.

    Some API commands may require authentication, some may not

    That’s also a task for the controller, to read and validate the request. If the user is not authenticated it would change the response

    Every API command should be open to extension via plugins (Notification on events, filtering of input/output paramters, etc.)

    Now this is the tricky part.. you could modify the controller and implement the strategy pattern. That’s a good idea if you’re planning to constantly change your plugins.

    In my case, i have multiple controllers and i use a Controller Factory that reads the request and returns a controller that manages that request.

    I am not really sure how do you want to implement your plugins. When you say Notification on events it sounds to me that you could use the observer pattern, and filtering of input/output paramters seems like a controller’s task.

    I hope this helps. Good Luck

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a REST API layer for my application using Zend_Rest_Controller. I have
I am developing a Java Desktop Application but have some confusions in choosing a
Developing a project of mine I realize I have a need for some level
When developing a plug-in to application, using the application API which doesn't run independently
Developing a .NET WinForms application: how can I check if the window is in
I am developing RESTful API for my application. All getters (that use HTTP GET)
Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux.
When developing a desktop application in .NET, is it possible to not require the
When developing a new web based application which version of html should you aim
I'm developing an application that needs to store lots of records in an organized

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.