Skip to content

API Standardization

Yossi Kolesnicov edited this page Jul 25, 2018 · 1 revision

To continue the example above, fetching all todo items for the example Todo app is done through the following API call: /api/todo

But in order to abstract that, so developers don't have to look up the API URL (and any parameters, if required, such as page, order, filter, etc), we create a service method and wrap the HTTP call:

// Example WITHOUT Paris!

class TodoService{
    getTodoItems():Promise<TodoItem[]> {
        return fetch('/api/todo')
            .then(data => data.map(item => new TodoItem(item)));
    }
}

If we assume authentication is solved (a cookie might be set in advance), the above should be fine. However, as our app grows, we'll need more and more of these methods, at least one for each data type. For example, we'd need getTodoLists to get all the todo lists, saveTodoItem to create a todo item or update one, deleteTodoItem for deleting one, etc.

Paris eliminates the need to define all these methods, since all CRUD operations are built into the library.

Clone this wiki locally