Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Glueckstiger's avatar

Naming API routes (not for views)?

Hi, I am coding my first SPA with Laravel, Inertia and Vue. What is the best practice for naming API routes for specific tasks or querying data? On the Vue side I make an axios call, but how do I name these routes? /api/v1/tasks/refresh_something or /api/v1/:resource:/refresh or /api/v1/a_select/get_options_values?

0 likes
1 reply
LaryAI's avatar
Level 58

When naming API routes for specific tasks or querying data in Laravel, it is recommended to follow a consistent and descriptive naming convention. Here are a few suggestions:

  1. Use a resource-based approach: If you are working with a specific resource, such as tasks, you can use a resource-based approach to name your routes. For example:
/api/v1/tasks/refresh

This route indicates that you are performing a refresh action on the tasks resource.

  1. Use a verb-based approach: If the action you are performing does not fit into a specific resource, you can use a verb-based approach. For example:
/api/v1/refresh-something

This route indicates that you are performing a refresh action on something, without tying it to a specific resource.

  1. Use a noun-based approach: If the action you are performing is more focused on retrieving data, you can use a noun-based approach. For example:
/api/v1/options-values

This route indicates that you are retrieving options values.

Ultimately, the choice of naming convention depends on your specific use case and preferences. The most important thing is to choose a convention that is clear, consistent, and easy to understand for both developers and API consumers.

Please or to participate in this conversation.