strapi/docs/start/api.md
2016-03-29 12:02:06 +02:00

1.3 KiB
Executable File

title
Your first API

Create your first API

It's pretty simple to generate an API with the Strapi CLI:

$ strapi generate:api apiName

For example, you can create a car API with:

$ strapi generate:api car

Update your database

Migrations allow you to define sets of schema changes so upgrading a database is a breeze.

Create a new migration file

To generate a migration file run:

$ strapi migrate:make connection_name migration_name

For example, if you want to create a migration file named new_car_model for the car API we just generated using the default connection the command looks like:

$ strapi migrate:make default new_car_model

Be careful, migrations are automatically generated based on your current database schema and models. We strongly advise you to manually verify those information.

Run the migrations

Once you have finished writing the migrations, you can update the database by running:

$ strapi migrate:run connection_name

So if you want to run the previous migration generated for the default connection you need to run:

$ strapi migrate:run default

Consume your API

You can take a look at the routes of the generated car API at ./api/car/config/routes.json.