API versioning and Custom apis

System Information
  • 3.5.1:
  • Windows 10:
  • Database:
  • >=10.16.0 <=14.x.x:
  • ^6.0.0:

So I need to version my APIs i.e v1/v2/v3 but I don’t see any routes file except the routes.json file inside config folder.

basically I want to do this:

__ |__contollers, models for some api
__ |__contollers, models for some api

is it possible to do so?
and I want to search something by it’s name(suppose country name) not it’s id.

Of course, create them with the same file structure that you mentioned above. In the same API folder, you can have multiple: controllers, models, services files. But a single routes file.
Take a look at the CLI commands documentation. There is shown how to create controllers/services/models inside another API.

/* First create the v1 API: */
yarn strapi generate:api v1

/* Then create others controllers/models/services inside it by using --api attribute. */
yarn strapi generate:controller countries --api v1
yarn strapi generate:model countries --api v1
yarn strapi generate:service countries --api v1

In this case, you will have the next APIs exposed: https://website.com/v1/countries and https://website.com/v1/cities

You already can search for something by name by using params (only when using default core controllers).

Let’s assume we have the following API: https://website.com/v1/countries

You can search countries by their name by using params: https://website.com/v1/countries?name=germany

Take a look at the parameters documentation.


You can get some ideas on API versioning by visiting the below link.

This may answer your question.


Sowthri S

Is it possible to generate a single-type api via the strapi CLI?
e.g. is there a flag like below?

strapi generate:api <singleType_name> --single

@jpizzle34 It is hardly to understand why this command is not working. For me I found a work-around to generate a single type by using the common api-generate command and manually file editing like this:

  1. run strapi generate:api <yourapi-typename> <attributes-to-add>(attributes are optional)
  2. if this was successful edit .settings.json and there add after the first curly bracket the line: "kind": "singleType",
  3. now it is defined as singleType in Strapi, but the not neccessary endpoints have to be removed, so that the server can restart So go to the routes.json which refers to your new type and remove all routes except the GET, PUT and DELETE ones.
  4. the single type should be shown from now on in admin-page. If not done by the generate command above, add new attributes to the new type with help of the content-type builder and also set permissions.

Hope this helps.

Please how can I make this method work in Strapi v4?