2
Watch
60
Star
5
Fork
66
Issue

The fastest way to create a simple Rest API, by defining database models and relations.

axe-api
axe-api
pushedAt 3 months ago

axe-api/axe-api


Markdownify
Axe API
npm version

The fastest way to create Rest API, by defining database models and relations.

Axe API has great documentation. Please check it out in here.

What Is Axe API?

Axe API is the fastest way to create Rest API by defining only database models and relationships between them. It is built on Knex.js, and its awesome active records pattern. On the other hand, you have another familiar thing, Express.

You are going to be able to develop an API 10 times faster with Axe API!

How It Works?

Express and Knex.js are great tools to create Node.js based applications. But usually, we code too much the same things to design an API. We aim to reduce code duplication and give you speed by using Axe API.

Axe API provides you the ability to separate your common tasks to build an API from your business logic. Axe API expects model definitions to analyze your routing structure. After you created your models and their relations between them, Axe API can handle all well-known API requests. Creating an API with 5 tables takes almost 15 minutes.

Shortly, Axe API performs three basic functions;

  • Analyzes your models and their relationships to create routes.
  • Handles all HTTP requests.
  • Separate your business logic from API best practices.

Let's assume that you have a model like this;

import { Model } from "axe-api";

class User extends Model {}

With this model, you will have all of the basic API routes for User resources. Axe API will create CRUD routes for you in the booting process and these routes would be completely ready to be handled and processed by Axe API. The following routes will be handled automatically;

  • POST api/users
  • GET api/users
  • GET api/users/:id
  • PUT api/users/:id
  • DELETE api/users/:id

This is the magic of Axe API!

Installation

Using Axe API in an application is very easy. We've created a CLI tool for you; axe-magic.

You can create a new Axe API project by using axe-magic. But first, you can install it in your development environment. When you installed it, you can be able to access axe-magic command via CLI. You can use the following command to install axe-magic to your machine;

$ npm i -g axe-magic
$ axe-magic --version
1.0.0

After that, creating a new project is very easy. Just you can execute the following command;

$ axe-magic new my-api

This command will pull axe-api-template project to your current directory with a new name, my-api.

To install your project's depencies, you can execute the following commands in the root directory;

$ cd my-api
$ npm install

To serve this application, you can execute the following command;

$ npm run start:dev

start:dev command use nodemon. If you haven't installed it yet, we suggest you install it first.

After that, your first Axe API application will be running in localhost:3000.

You will see the following API response if you visit localhost:3000.

{
  "name": "AXE API",
  "description": "The best API creation tool in the world.",
  "aim": "To kill them all!"
}

If you can see that response, it means that your project is running properly.

Documentation

Axe API has great documentation. Please check it out in here.

How To Run Integration Tests

You have to have Docker and Docker Compose on your local development environment to run integration tests.

Execute the following commands to prepare the integration app

cd tests/integrations && npm install && npm ci && npm run build --if-present

Execute the following commands to prepare the database;

docker-compose -f "./tests/integrations/docker-compose.mysql8.yml" up -d --build

To down the database, you can use the following command; docker-compose -f "./tests/integrations/docker-compose.mysql8.yml" up -d --build

You can execute the following command to execute tests;

npm run test:integration:mysql8

License

MIT License

ucloud ads