Unverified Commit d9f0b152 authored by Hong Minhee's avatar Hong Minhee
Browse files

Document how to construct URIs

[ci skip]
parent 5829c3ef
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -275,3 +275,25 @@ federation
[2]: https://socialhub.activitypub.rocks/t/fep-8b32-object-integrity-proofs/2725/79?u=hongminhee
[`CryptoKeyPair`]: https://developer.mozilla.org/en-US/docs/Web/API/CryptoKeyPair
[Deno KV]: https://deno.com/kv


Constructing actor URIs
-----------------------

To construct an actor URI, you can use the `Context.getActorUri()` method.
This method takes a bare handle and returns a dereferenceable URI of the actor.

The below example shows how to construct an actor URI:

~~~~ typescript
ctx.getActorUri("john_doe")
~~~~

In the above example, the `Context.getActorUri()` method generates the
dereferenceable URI of the actor with the bare handle `"john_doe"`.

> [!NOTE]
>
> The `Context.getActorUri()` method does not guarantee that the actor
> URI is always dereferenceable for every argument.  Make sure that
> the argument is a valid bare handle before calling the method.
+141 −0
Original line number Diff line number Diff line
@@ -313,6 +313,26 @@ federation
  });
~~~~

### Constructing outbox collection URIs

To construct an outbox collection URI, you can use the `Context.getOutboxUri()`
method.  This method takes the actor's handle and returns the dereferenceable
URI of the outbox collection of the actor.

The following shows how to construct an outbox collection URI of an actor named
`"alice"`:

~~~~ typescript
ctx.getOutboxUri("alice")
~~~~

> [!NOTE]
>
> The `Context.getOutboxUri()` method does not guarantee that the outbox
> collection actually exists.  It only constructs a URI based on the given
> handle, which may respond with `404 Not Found`.  Make sure to check if the
> handle is valid before calling the method.


Inbox
-----
@@ -347,6 +367,26 @@ federation
> The path for the inbox collection dispatcher must match the path for the inbox
> listeners.

### Constructing inbox collection URIs

To construct an inbox collection URI, you can use the `Context.getInboxUri()`
method.  This method takes the actor's handle and returns the dereferenceable
URI of the inbox collection of the actor.

The following shows how to construct an inbox collection URI of an actor named
`"alice"`:

~~~~ typescript
ctx.getInboxUri("alice")
~~~~

> [!NOTE]
>
> The `Context.getInboxUri()` method does not guarantee that the inbox
> collection actually exists.  It only constructs a URI based on the given
> handle, which may respond with `404 Not Found`.  Make sure to check if the
> handle is valid before calling the method.


Following
---------
@@ -382,6 +422,25 @@ federation
  .setFirstCursor(async (ctx, handle) => "");
~~~~

### Constructing following collection URIs

To construct a following collection URI, you can use
the `Context.getFollowingUri()` method.  This method takes the actor's handle
and returns the dereferenceable URI of the following collection of the actor.

The following shows how to construct a following collection URI of an actor
named `"alice"`:

~~~~ typescript
ctx.getFollowingUri("alice")
~~~~

> [!NOTE]
> The `Context.getFollowingUri()` method does not guarantee that the following
> collection actually exists.  It only constructs a URI based on the given
> handle, which may respond with `404 Not Found`.  Make sure to check if the
> handle is valid before calling the method.


Followers
---------
@@ -470,6 +529,26 @@ federation
> world, you should filter the actors in the database query to improve the
> performance.

### Constructing followers collection URIs

To construct a followers collection URI, you can use
the `Context.getFollowersUri()` method.  This method takes the actor's handle
and returns the dereferenceable URI of the followers collection of the actor.

The following shows how to construct a followers collection URI of an actor
named `"alice"`:

~~~~ typescript
ctx.getFollowersUri("alice")
~~~~

> [!NOTE]
>
> The `Context.getFollowersUri()` method does not guarantee that the followers
> collection actually exists.  It only constructs a URI based on the given
> handle, which may respond with `404 Not Found`.  Make sure to check if the
> handle is valid before calling the method.


Liked
-----
@@ -503,6 +582,26 @@ federation
  });
~~~~

### Constructing liked collection URIs

To construct a liked collection URI, you can use the `Context.getLikedUri()`
method.  This method takes the actor's handle and returns the dereferenceable
URI of the liked collection of the actor.

The following shows how to construct a liked collection URI of an actor named
`"alice"`:

~~~~ typescript
ctx.getLikedUri("alice")
~~~~

> [!NOTE]
>
> The `Context.getLikedUri()` method does not guarantee that the liked
> collection actually exists.  It only constructs a URI based on the given
> handle, which may respond with `404 Not Found`.  Make sure to check if the
> handle is valid before calling the method.


Featured
--------
@@ -529,6 +628,27 @@ federation
  });
~~~~

### Constructing featured collection URIs

To construct a featured collection URI, you can use
the `Context.getFeaturedUri()` method.  This method takes the actor's handle
and returns the dereferenceable URI of the featured collection of the actor.

The following shows how to construct a featured collection URI of an actor named
`"alice"`:

~~~~ typescript
ctx.getFeaturedUri("alice")
~~~~

> [!NOTE]
>
> The `Context.getFeaturedUri()` method does not guarantee that the featured
> collection actually exists.  It only constructs a URI based on the given
> handle, which may respond with `404 Not Found`.  Make sure to check if the
> handle is valid before calling the method.



Featured tags
-------------
@@ -560,3 +680,24 @@ federation
    return { items };
  });
~~~~

### Constructing featured tags collection URIs

To construct a featured tags collection URI, you can use
the `Context.getFeaturedTagsUri()` method.  This method takes the actor's handle
and returns the dereferenceable URI of the featured tags collection of
the actor.

The following shows how to construct a featured tags collection URI of an actor
named `"alice"`:

~~~~ typescript
ctx.getFeaturedTagsUri("alice")
~~~~

> [!NOTE]
>
> The `Context.getFeaturedTagsUri()` method does not guarantee that the featured
> tags collection actually exists.  It only constructs a URI based on the given
> handle, which may respond with `404 Not Found`.  Make sure to check
> if the handle is valid before calling the method.
+27 −0
Original line number Diff line number Diff line
@@ -242,3 +242,30 @@ federation
> [!NOTE]
> Activities with invalid signatures/proofs are silently ignored and not passed
> to the error handler.


Constructing inbox URIs
-----------------------

To construct an inbox URI, you can use the `~Context.getInboxUri()` method.
This method optionally takes a handle of an actor and returns a dereferenceable
URI of the inbox of the actor.  If no argument is provided, the method returns
the shared inbox URI.

The following shows how to construct an inbox URI of an actor named `"alice"`:

~~~~ typescript
ctx.getInboxUri("alice")
~~~~

> [!NOTE]
> The `~Context.getInboxUri()` method does not guarantee that the inbox
> actually exists.  It only constructs a URI based on the given handle,
> which may respond with `404 Not Found`.  Make sure to check if the handle
> is valid before calling the method.

The following shows how to construct a shared inbox URI:

~~~~ typescript
ctx.getInboxUri()
~~~~
+21 −0
Original line number Diff line number Diff line
@@ -57,3 +57,24 @@ 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


Constructing object URIs
------------------------

To construct an object URI, you can use the `Context.getObjectUri()` method.
This method takes a class and URL arguments, and returns a dereferenceable URI
of the object.

The below example shows how to construct an object URI:

~~~~ typescript
ctx.getObjectUri(Note, { handle: "alice", id: "123" });
~~~~

> [!NOTE]
>
> The `Context.getObjectUri()` method does not guarantee that the object
> actually exists.  It only constructs a URI based on the given class and URL
> arguments, which may respond with `404 Not Found`.  Make sure to check
> if the arguments are valid before calling the method.
+0 −1
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@
    "@deno/dnt": "jsr:@deno/dnt@^0.41.2",
    "@fedify/fedify": "../../src/mod.ts",
    "@fedify/fedify/federation": "../../src/federation/mod.ts",
    "@fedify/fedify/httpsig": "./httpsig/mod.ts",
    "@fedify/fedify/nodeinfo": "./nodeinfo/mod.ts",
    "@fedify/fedify/runtime": "../../src/runtime/mod.ts",
    "@fedify/fedify/vocab": "../../src/vocab/mod.ts",