Skip to content

Endpoints and paths ​

An endpoint is a method and a path that your mock server answers, such as GET /users/:id. This page covers creating endpoints, the path patterns, how Mock Studio picks an endpoint when several fit, and organising the list.

Create an endpoint ​

  1. In the side panel, select + beside Endpoints.

  2. In Add an endpoint, choose Blank endpoint, or pick a template.

  3. Set the method and the path at the top of the editor.

  4. Give it an Endpoint name you will recognise in the list and the Live log.

A blank endpoint is GET /hello with one 200 response. Templates are ordinary endpoints with useful settings already filled in. You can change everything afterwards.

TemplateWhat you get
Simple JSON responseGET /something returning a fixed JSON object
Resource by idGET /items/:id that sends the id back
Create (POST) endpointPOST /items returning 201 with a new id
Protected endpointGET /me that requires an Authorization header
Flaky service (random errors)GET /flaky returning 500 about 20% of the time
Slow endpointGET /slow with a 2 second delay
Retry sequenceGET /retry that fails twice, then succeeds
List with paginationGET /items returning a list and the requested page

Methods ​

The method dropdown offers ANY, GET, POST, PUT, PATCH, DELETE, HEAD and OPTIONS.

  • ANY answers every method on that path. Use it when the method does not matter, or pair it with a rule on HTTP method to answer methods differently. See Conditional rules.
  • HEAD requests have a fallback. If no endpoint answers HEAD for a path, Mock Studio uses the matching GET endpoint and sends its status and headers with no body, which is how HTTP defines HEAD.
  • OPTIONS endpoints are only reached when CORS is turned off for the project. While Enable CORS is on, the server answers every OPTIONS request itself with 204. See Auth, CORS and project settings.

Path templates ​

Type the path in the field beside the method. A leading / is added if you leave it out. Select the ? button in the field to open Path patterns, a short reminder of the syntax.

PatternMatchesValue available as
/usersExactly /users
/users/:idOne segment in place of :id, such as /users/42{{params.id}}
/files/*Any single segment, such as /files/report{{params.wildcard0}}
/assets/**Everything after it, such as /assets/img/logo.png{{params.rest}}

A segment is the text between two slashes.

Details worth knowing ​

  • Query strings are ignored when matching. /users?page=2 is answered by the /users endpoint. Read the query with {{query.page}} or a rule on Query param.
  • A trailing slash does not matter. /users/ and /users are the same path.
  • Fixed text is case-sensitive. /Users does not match /users.
  • A parameter or a single wildcard needs exactly one segment. /users/:id does not match /users or /users/42/orders.
  • A wildcard is a whole segment. /files/*.png is not a pattern; the * must stand alone between slashes.
  • The double wildcard can match nothing. /assets/** also matches /assets, with an empty rest.
  • The double wildcard ends the template. Anything you write after ** is ignored.
  • Several wildcards are numbered. In /a/*/b/* the values are wildcard0 and wildcard1.
  • Captured values are URL-decoded. /users/ana%20li gives ana li.

You can name a parameter anything: /orders/:orderId/items/:itemId gives {{params.orderId}} and {{params.itemId}}.

Which endpoint wins ​

When a request arrives, Mock Studio looks at every enabled endpoint whose method fits (the same method, or ANY) and whose path template fits. If more than one fits, the most specific path wins.

Each segment of a template scores points:

SegmentPoints
Fixed text, such as users3
:name or *1
**0

The endpoint with the highest total answers. On a tie, the endpoint that is higher in the list answers.

Example. A project has these three GET endpoints, and a client calls GET /users/me:

Endpoint pathFits /users/me?Score
/users/meYes3 + 3 = 6
/users/:idYes3 + 1 = 4
/users/**Yes3 + 0 = 3

/users/me answers. A call to /users/42 is answered by /users/:id, and /users/42/orders by /users/**.

Good to know

The method is not part of the score. An ANY endpoint and a GET endpoint with the same path tie, so the one higher in the list answers GET requests. Two endpoints with the same method and the same path shape, such as /users/:id and /users/:userId, also tie, and the lower one is never reached.

When nothing matches ​

If no enabled endpoint fits, the server forwards the request to a real API when a proxy address is set (see Proxy and record). Otherwise it answers 404 with this body:

json
{
  "error": "not_found",
  "message": "No mock endpoint matched GET /user",
  "hint": "Add this endpoint in Mock Studio, or enable proxy passthrough."
}

The request shows in the Live section with a no match tag, which is the fastest way to spot a typo in a path.

Enable or disable an endpoint ​

Turn off the Enabled switch at the top right of the editor, or choose Disable from the endpoint's ⋯ menu in the list. The server then ignores the endpoint as if it did not exist, and the list marks it as disabled. Nothing is deleted. Turn the switch back on, or choose Enable, to bring it back.

Disabling is useful for testing what your app does when a route is missing, or for keeping two versions of an endpoint and switching between them.

Duplicate, move and delete ​

Open the ⋯ menu on an endpoint in the list:

Menu itemWhat it does
Disable / EnableStops or resumes answering, without deleting.
Move to folder…Puts the endpoint in a folder.
DuplicateAdds a copy named with (copy) directly below, with the same method, path and responses.
DeleteRemoves the endpoint.

WARNING

Delete removes the endpoint at once, with no confirmation and no undo. If you might want it back, use Disable instead, or export the project first.

A duplicate has the same method and path as the original, so the original, being higher in the list, keeps answering. Change the copy's path or method, or disable the original.

Folders ​

Folders group endpoints in the list. They do not change any URL.

An endpoints list with an Orders folder holding three endpoints
  1. 1Folder — Click to collapse or expand it. The number on the right counts its endpoints.
  2. 2Folder actions — Rename folder and Ungroup.
  3. 3Breadcrumbs — The folder appears in the path at the top.
  1. Open the ⋯ menu on an endpoint and choose Move to folder….

  2. In Folder, type a folder name, or select one of the existing folders shown below the field.

    Use / to nest folders: Users/Admin puts the endpoint in Admin inside Users. Leave the field empty to move the endpoint back to the top level.

  3. Select Move.

A folder exists as long as an endpoint is in it. To change a folder, open its ⋯ menu:

  • Rename folder changes the name for every endpoint inside.
  • Ungroup removes the folder and keeps its endpoints, moving them up one level.

Type in Search endpoints to filter the list. It matches endpoint names, paths, folders and methods, so post shows every POST endpoint and orders shows everything with that word in its name, path or folder.

Check yourself ​

QuizEndpoints and paths

Question 1 of 6

A project has these three enabled GET endpoints. A client calls GET /orders/7/items. Which one answers?

/orders/:id
/orders/**
/orders/:id/items
Score: 0

Next steps ​