In order to prefix all your mock API routes,
Open the Environment Settings by clicking on the tab at the top of the window:
Then, fill the API prefix input at the top of the environment Settings:
The prefix will appear under your environment name in the environments list. All your environment's routes will now be prefixed and available at the following address http://localhost:port/myprefix/myroute
instead of http://localhost:port/myroute
.
You need to restart the environment for the change to take effect.
Mockoon uses Express to run the mock servers. In general, most of the Express' documentation applies. Please refer to the routing documentation for more information and examples on the following topics.
Routes are declared in the server in the order displayed in the application (inside folders or not). This means that the first ones take precedence over the following ones.
One consequence is that a route parameter will capture any value at the specific URL segment. For example, /users/:id
or /users/*
will intercept /users/search
. The more specific "search" route should be declared first. You can always reorder routes by dragging and dropping them.
Routes support certain patterns and a subset of regular expressions. Here are some examples of the available ones:
/path/*
will match /path/anything
./ab?cd
will match /acd
and /abcd
./ab+cd
will match abcd
, abbcd
, abbbcd
, and so on./ab(cd)?e
will match /abe
and /abcde
.For a complete overview of the patterns available, please refer to Express' route paths documentation.
💡 To use parentheses in your path as a normal character, you can escape them by either using a backslashe \
or square brackets []
:
/part1[(]part2[)]
> /part1\(part2\)
Route parameters can be defined in routes by using a colon :
. The name of a parameter can only contains the following characters A-Za-z0-9_
.
For a complete overview on how to use and declare route parameters, please refer to Express' route parameters documentation.
You can also retrieve the route parameters by using the {{urlParam 'paramName'}}
templating helper.
💡 To use a colon :
in your route path as a normal character, you can escape it by either using double backslashes \\
or square brackets []
:
/part1[:]part2
> /part1\\:part2
Routes must be declared without query parameters as they are not part of the route path. They can only be added to the request when calling an endpoint.
Query parameters can be retrieved with the queryParam
and queryParamRaw
helpers and are available in the response rules to check their content and serve different responses based on them.
Arrays and objects are supported in the query string. For more information, please refer to the query parameters documentation.
You can disable a route by clicking on the Toggle route entry in the route dropdown menu. The route will be marked with a red border and will not be accessible until you enable it again.
You can also disable all routes in a folder by using the Toggle direct child routes entry in the folder dropdown menu.
When running your mock API using the CLI, you can disable routes using the --disable-routes
flag followed by a route UUID or keyword/name or a folder keyword/name: mockoon start -d ./data.json --disable-routes myroute folder2
. You can also disable all routes by using a wildcard: mockoon start -d ./data.json --disable-routes "*"
.
When using the serverless package, you can disable routes using the disabledRoutes
option.