-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #33
- Loading branch information
Showing
14 changed files
with
744 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
description: >- | ||
You can register an object dispatcher so that Fedify can dispatch an | ||
appropriate object by its class and URL arguments. This section explains | ||
how to register an object dispatcher. | ||
prev: | ||
text: Collections | ||
link: ./collections.md | ||
next: | ||
text: Access control | ||
link: ./access-control.md | ||
--- | ||
|
||
Object dispatcher | ||
================= | ||
|
||
*This API is available since Fedify 0.7.0.* | ||
|
||
In ActivityPub, [objects] are entities that can be attached to activities or | ||
other objects. Objects sometimes need to be resolved by their dereferenceable | ||
URIs. To let objects be resolved, you can register object dispatchers so that | ||
Fedify can dispatch an appropriate object by its class and URL arguments. | ||
|
||
An object dispatcher is a callback function that takes a `Context` object and | ||
URL arguments, and returns an object. Every object dispatcher has one or more | ||
URL parameters that are used to dispatch the object. The URL parameters are | ||
specified in the path pattern of the object dispatcher, e.g., `/notes/{id}`, | ||
`/users/{handle}/articles/{id}`. | ||
|
||
The below example shows how to register an object dispatcher: | ||
|
||
~~~~ typescript {7-19} | ||
import { Federation, Note } from "@fedify/fedify"; | ||
|
||
const federation = new Federation({ | ||
// Omitted for brevity; see the related section for details. | ||
}); | ||
|
||
federation.setObjectDispatcher( | ||
Note, | ||
"/users/{handle}/notes/{id}", | ||
async (ctx, { handle, id }) => { | ||
// Work with the database to find the note by the author's handle and the note ID. | ||
if (note == null) return null; // Return null if the note is not found. | ||
return new Note({ | ||
id: ctx.getObjectUri(Note, { handle, id }), | ||
content: note.content, | ||
// Many more properties... | ||
}); | ||
} | ||
); | ||
~~~~ | ||
|
||
In the above example, the `~Federation.setObjectDispatcher()` method registers | ||
an object dispatcher for the `Note` class and the `/users/{handle}/notes/{id}` | ||
path. This pattern syntax follows the [URI Template] specification. | ||
|
||
[objects]: https://www.w3.org/TR/activitystreams-core/#object | ||
[URI Template]: https://datatracker.ietf.org/doc/html/rfc6570 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.