Skip to content

API Overview

An API is an interface that software developers use to programmatically interact with software components or resources outside of their own code. Know More About API

This section covers concepts about the API implementation.

Why Base Controller and Base Service ?

It is a common practice for developers to create a "BaseController" or "BaseService" or a BaseAnything class to use for common functionality, and then derive other things from that BaseWhatever in order to reuse that functionality. This is just basic Object Oriented Programming technique i.e Inheritance, and have nothing specific to do with MVCS or any other architecture.

On the children class, we use the extends keyword to declare the parent class we want to inherit from. Then on the constructor method we use the super function to indicate that property is declared on the parent class.

Controller

class ApiUserController extends BaseController {
    constructor(opts) {
        super(opts);
    }
}

Service

class ApiUserService extends BaseService {
    constructor() {
        super(apiUsers);
    }
}

All too often, people put all kinds of stuff in these base classes for convenience, because it's easier than creating some other mechanism to share code or data in a better way.