DEV Community

Özgür Adem Işıklı
Özgür Adem Işıklı

Posted on

What is Axe API

A Rest API consists of two components: common elements that require time and effort, such as best practices and shared features, and custom logic that distinguishes one API from another.

Axe API Schema

Axe API is a TypeScript-based Node.js framework designed to eliminate the need for repetitive tasks associated with common elements while allowing developers to focus on custom logic. It offers a comprehensive structure for your API, including numerous features and best practices that will save you time.

Faster API development

Axe API simplifies the development process of your API by taking care of basic tasks such as routing, validating, querying, and handling HTTP requests.

This feature allows developers to focus on custom logic while developing their Axe API projects, which results in faster development times.

Additionally, the framework offers dedicated areas where developers can add their own custom logic.

Model-driven API

Unlike other frameworks, Axe API doesn't require a Controller file. Instead, the framework focuses on your project's model files, which are the most critical aspect of the project.

Axe API automatically reads and understands your models and their relationships with each other, creating the API without any manual intervention.

Let's check out the following model;

import { Model } from "axe-api";

class Category extends Model {
  // todo...
}

export default Category;
Enter fullscreen mode Exit fullscreen mode

Once you define your model in Axe API, the framework analyzes it and automatically creates all CRUD (Create, Read, Update, Delete) routes for you.

In addition to creating the routes, Axe API also handles all of the CRUD operations, so you don't need to do anything at all.

Securing data input

Security is a top priority for Axe API. To enable clients to add new records to your database table, you must specify which fields can be filled.

See the example below for reference.

import { Model } from "axe-api";

class Category extends Model {
  get fillable() {
    return ["name", "description"];
  }
}

export default Category;
Enter fullscreen mode Exit fullscreen mode

In the provided example, the name and description fields are designated as fillable, meaning that clients can create a new record on your table by submitting an HTTP POST request containing these fields to your API.

Automated validation

As a developer, it is crucial to validate all data before creating a new record in the database.

With Axe API, there is no need to write extensive code in your Controller file. Instead, developers should include validation rules in their model files, and Axe API handles the rest of the validation process.

import { Model } from "axe-api";

class Category extends Model {
  get fillable() {
    return ["name", "description"];
  }

  get validations() {
    return {
      name: "required|min:3|max:100",
      description: "max:100",
    };
  }
}

export default Category;
Enter fullscreen mode Exit fullscreen mode

Axe API provides detailed error messages if a client submits invalid data in an HTTP request.

Query your models

After defining the models for your API, your database model is immediately queryable.

For instance, you can access all the data for the Category model by using the following URL.

GET http://localhost:4000/api/v1/categories?fields=name,description
Enter fullscreen mode Exit fullscreen mode
{
  "data": [
    {
      "id": 1,
      "name": "Frameworks",
      "description": "Web application development tools."
    }
  ],
  "pagination": {
    "total": 1,
    "lastPage": 1,
    "perPage": 10,
    "currentPage": 1,
    "from": 0,
    "to": 1
  }
}
Enter fullscreen mode Exit fullscreen mode

Axe API has built-in pagination support.

Additionally, developers can utilize various query parameters such as fields, sort, page, and more to obtain optimal results from the API.

https://axe-api.com

Top comments (0)