Skip to content

Commit

Permalink
Add documentation for mockoon/mockoon#221
Browse files Browse the repository at this point in the history
  • Loading branch information
255kb committed Oct 2, 2023
1 parent dcc61a5 commit abd19c4
Show file tree
Hide file tree
Showing 24 changed files with 42 additions and 16 deletions.
38 changes: 38 additions & 0 deletions content/docs/latest/route-responses/global-routes-with-rules.md
Expand Up @@ -9,3 +9,41 @@ order: 320
# Global routes with rules

---

If you want to serve the same responses based on the same rules for all or part of your endpoints, you can create global routes using the **fallback mode** and a **wildcard path**. This is useful if you want to protect all your endpoints by checking if an `Authorization` header is present or if you want to verify that all your requests contain a specific property in their body.

Three parts are required to create a global route:

## 1. Create a wildcard route

To create a global route, you first need to create a new HTTP route that will match all the endpoints you want to protect. To do so, create a new route and select "All methods" in the method dropdown:

![wildcard route on all methods{599x329}](docs-img:create-wildcard-route.png)

In this example, the wildcard route is placed above the `GET /users` route, which is important as it will be [evaluated first](docs:api-endpoints/routing#routes-order) and catch all the requests. You can create it first or move it up in the routes list with a drag and drop.

> 💡 You can also create a wildcard route that only matches a specific method, like `GET` or `POST`, instead of "All methods", if you want to protect all your `POST` endpoints, for example.
> Finally, you can create a wildcard route that matches all the endpoints starting with a specific path, like `/users/*` instead of `/*`. You can use this method to protect all your `/users/something` endpoints but not the `/users` one.
## 2. Create your global responses and rules

The second step is to create one or more responses with rules. For example, you can create a response checking that the request contains an `Authorization` header and returning a `401` error if's not present.
To follow this example, use the existing response or create a new one and set the status code to `401`:

![create response with status code 401{1006x261}](docs-img:response-status-code-401.png)

Add a new rule to this response by clicking on the "add rule" button and selecting the "Header" rule type. Then, set the rule to check that the `Authorization` header is null as we want to return a `401` error if it is not present:

![create rule to check that the Authorization header is null{987x311}](docs-img:response-rule-header-null.png)

> 💡 You can create more responses with associated rules to verify more criteria on the request and serve different responses accordingly (errors, etc.).
## 3. Activate the fallback mode

Once your route is created and your responses customized, activate the fallback mode by clicking on the "fallback" icon next to the response list:

![Activate fallback mode{999x174}](docs-img:activate-fallback-mode.png)

This will automatically pass the request to the next route when none of the [responses' rules](docs:route-responses/dynamic-rules) match.

> 📘 Learn more about the [fallback mode](docs:route-responses/multiple-responses#fallback-mode) in our documentation.
2 changes: 1 addition & 1 deletion content/docs/latest/templating/mockoon-helpers.md
@@ -1,5 +1,5 @@
---
title: Helpers
title: Custom helpers
meta:
title: Create dynamic responses with templating helpers
description: "Create dynamic fake data for your mock server with Mockoon's templating helpers. All formats are supported: JSON, CSV, HTML, etc."
Expand Down
2 changes: 1 addition & 1 deletion content/docs/latest/templating/overview.md
Expand Up @@ -10,7 +10,7 @@ order: 500

---

Mockoon implements [Handlebars](https://handlebarsjs.com/), [Faker.js v7.6.0](https://fakerjs.dev/), and a set of custom helpers to create dynamic responses. This templating system is supported in the response's **body**, **headers**, **file content**, and **file path**. You will find below a global overview of how and where you can use helpers. You can also check the [available helpers](#available-helpers) on specific documentation pages.
Mockoon implements [Handlebars](https://handlebarsjs.com/), [Faker.js v7.6.0](https://fakerjs.dev/), and a set of custom helpers to create dynamic responses. This templating system is supported in the [**data buckets**](#content-of-a-data-bucket), [**response's body**](#body-and-file-content-templating), [**header values**](#headers-and-rule-values), [**file content**](#body-and-file-content-templating), [**file path**](#file-input-templating) and [**rule values**](#headers-and-rule-values). You will find below a global overview of how and where you can use helpers. You can also check the [available helpers](#available-helpers) on specific documentation pages.

## Helpers

Expand Down
4 changes: 2 additions & 2 deletions content/releases/5.0.0.md
@@ -1,7 +1,7 @@
---
meta:
title: Mockoon release v5.0.0
description: Discover Mockoon applications new v5.0.0 release with TODO
description: Discover Mockoon applications new v5.0.0 release with JSONPath support, global routes with rules and more.
date: '2023-TODO'
---

Expand Down Expand Up @@ -52,7 +52,7 @@ It is now possible to create routes that will match any HTTP method. You can now
Thanks to the [response fallback mode](https://mockoon.com/docs/latest/route-responses/multiple-responses/#fallback-mode) introduced in v4.1.0, it was already possible to create wildcard routes containing "global" rules, like validating the presence of an `Authorization` header, or verifying that the request body contains a specific property.
The only missing piece was the ability to create a global route that would match any HTTP method, which is now possible with the new feature above.

Head over to our new ["Global routes with rules"](https://mockoon.com/TODO) tutorial to learn how to create reusable responses and rules and apply them to all your routes.
Head over to our new ["Global routes with rules"](https://mockoon.com/docs/latest/route-responses/global-routes-with-rules/) documentation section to learn how to create reusable responses and rules and apply them to all your routes.

(Issue [#221](https://github.com/mockoon/mockoon/issues/221))

Expand Down
12 changes: 0 additions & 12 deletions content/tutorials/create-global-responses-and-rules.md

This file was deleted.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit abd19c4

Please sign in to comment.