# Resource Handler

The Resource Handler Interface ([See Interface here](https://doc.deno.land/https/raw.githubusercontent.com/mandarineorg/mandarinets/master/main-core/Mandarine.ns.ts#Mandarine.MandarineCore.IResourceHandler)) allows you to create a resource handler that can be added to the Resource Handler Registry.

## Methods

| Name                       | Description                                                                                                |
| -------------------------- | ---------------------------------------------------------------------------------------------------------- |
| addResourceHandler         | Adds one or multiple RegExp route to be intercepted. When intercepted, `resourceResolver` will be invoked. |
| addResourceHandlerLocation | Adds one or multiple locations where the resources are located internally.                                 |
| addResourceHandlerIndex    | Adds one or multiple paths to index files for each resource location.                                      |
| addResourceResolver        | Adds the resolver that will read & resolve the requests for declared routes.                               |

## Example

```typescript
new ResourceHandler()
            .addResourceHandler(
            new RegExp("/js/(.*)"),
            new RegExp("/css/(.*)"), 
            new RegExp("/(.*)")
            )
            .addResourceHandlerLocation(
            "./src/main/resources/static/js", 
            "./src/main/resources/static/css", 
            "./src/main/resources/static")
            .addResourceHandlerIndex(
            undefined, 
            undefined, 
            "index.html")
            .addResourceResolver(new MandarineResourceResolver())
```

In the above example, we are declaring that routes starting with `/js/` should go to `./src/main/resources/static/js` and so on. We are also defining that the root routes (`/(.*)`) should have an index file which is `index.html` in `./src/main/resources/static`

Our resolver for such requests is `MandarineResourceResolver` , which is the default resolver by Mandarine. This resolver is used in [Mandarine static content](https://mandarineframework.gitbook.io/mandarine-ts/mandarine-mvc/serving-static-content), but it can also be used for multiple handlers.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mandarineframework.gitbook.io/mandarine-ts/v1.0.1/mandarine-core/resource-handlers/resource-handler.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
