Skip to content

Commit 9f13cc5

Browse files
authored
Merge pull request #170 from HarperDB/export-resources
Document server.resources
2 parents adb2ea2 + d74bd1c commit 9f13cc5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

docs/technical-details/reference/globals.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,24 @@ This records the provided value as a metric into Harper's analytics. Harper effi
262262
This returns the user object with permissions/authorization information based on the provided username. This does not verify the password, so it is generally used for looking up users by username. If you want to verify a user by password, use [`server.authenticateUser`](globals.md#serverauthenticateuserusername-password-user).
263263

264264
### `server.authenticateUser(username, password): Promise<User>`
265-
This returns the user object with permissions/authorization information based on the provided username. The password will be verified before returning the user object (if the password is incorrect, an error will be thrown).
265+
This returns the user object with permissions/authorization information based on the provided username. The password will be verified before returning the user object (if the password is incorrect, an error will be thrown).
266+
267+
### `server.resources: Resources`
268+
This provides access to the map of all registered resources. This is the central registry in Harper for registering any resources to be exported for use by REST, MQTT, or other components. Components that want to register resources should use the `server.resources.set(name, resource)` method to add to this map. Exported resources can be found by passing in a path to `server.resources.getMatch(path)` which will find any resource that matches the path or beginning of the path.
269+
270+
#### `server.resources.set(name, resource, exportTypes?)`
271+
Register a resource with the server. For example:
272+
```
273+
class NewResource extends Resource {
274+
}
275+
server.resources.set('NewResource', Resource);
276+
// or limit usage:
277+
server.resources.set('NewResource', Resource, { rest: true, mqtt: false, 'my-protocol': true });
278+
```
279+
#### `server.resources.getMatch(path, exportType?)`
280+
Find a resource that matches the path. For example:
281+
```
282+
server.resources.getMatch('/NewResource/some-id');
283+
// or specify the export/protocol type, to allow it to be limited:
284+
server.resources.getMatch('/NewResource/some-id', 'my-protocol');
285+
```

0 commit comments

Comments
 (0)