Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curvy-feet-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": minor
---

Update create-cloudflare hello-world Durable Objects templates to use `getByName()`
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@ export default {
* @returns {Promise<Response>} The response to be sent back to the client
*/
async fetch(request, env, ctx) {
// Create a `DurableObjectId` for an instance of the `MyDurableObject`
// class named "foo". Requests from all Workers to the instance named
// "foo" will go to a single globally unique Durable Object instance.
const id = env.MY_DURABLE_OBJECT.idFromName("foo");

// Create a stub to open a communication channel with the Durable
// Object instance.
const stub = env.MY_DURABLE_OBJECT.get(id);
// Create a stub to open a communication channel with the Durable Object
// instance named "foo".
//
// Requests from all Workers to the Durable Object instance named "foo"
// will go to a single remote Durable Object instance.
const stub = env.MY_DURABLE_OBJECT.getByName("foo");

// Call the `sayHello()` RPC method on the stub to invoke the method on
// the remote Durable Object instance
// the remote Durable Object instance.
const greeting = await stub.sayHello("world");

return new Response(greeting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ async def say_hello(self, name):
"""
class Default(WorkerEntrypoint):
async def fetch(self, request):
# Create a `DurableObjectId` for an instance of the `MyDurableObject`
# class named "foo". Requests from all Workers to the instance named
# "foo" will go to a single globally unique Durable Object instance.
id = self.env.MY_DURABLE_OBJECT.idFromName("foo")
# Create a stub to open a communication channel with the Durable Object
# instance named "foo".
#
# Requests from all Workers to the Durable Object instance named "foo"
# will go to a single remote Durable Object instance.
stub = self.env.MY_DURABLE_OBJECT.getByName("foo")

# Create a stub to open a communication channel with the Durable
# Object instance.
stub = self.env.MY_DURABLE_OBJECT.get(id)

# Call the `say_hello()` RPC method on the stub to invoke the method on
# the remote Durable Object instance
# Call the `say_hello()` RPC method on the stub to invoke the method on
# the remote Durable Object instance.
greeting = await stub.say_hello("world")

return Response(greeting)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,15 @@ export default {
* @returns The response to be sent back to the client
*/
async fetch(request, env, ctx): Promise<Response> {
// Create a `DurableObjectId` for an instance of the `MyDurableObject`
// class named "foo". Requests from all Workers to the instance named
// "foo" will go to a single globally unique Durable Object instance.
const id: DurableObjectId = env.MY_DURABLE_OBJECT.idFromName("foo");

// Create a stub to open a communication channel with the Durable
// Object instance.
const stub = env.MY_DURABLE_OBJECT.get(id);
// Create a stub to open a communication channel with the Durable Object
// instance named "foo".
//
// Requests from all Workers to the Durable Object instance named "foo"
// will go to a single remote Durable Object instance.
const stub = env.MY_DURABLE_OBJECT.getByName("foo");

// Call the `sayHello()` RPC method on the stub to invoke the method on
// the remote Durable Object instance
// the remote Durable Object instance.
const greeting = await stub.sayHello("world");

return new Response(greeting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@ export default {
* @returns {Promise<Response>} The response to be sent back to the client
*/
async fetch(request, env, ctx) {
// Create a `DurableObjectId` for an instance of the `MyDurableObject`
// class named "foo". Requests from all Workers to the instance named
// "foo" will go to a single globally unique Durable Object instance.
const id = env.MY_DURABLE_OBJECT.idFromName("foo");

// Create a stub to open a communication channel with the Durable
// Object instance.
const stub = env.MY_DURABLE_OBJECT.get(id);
// Create a stub to open a communication channel with the Durable Object
// instance named "foo".
//
// Requests from all Workers to the Durable Object instance named "foo"
// will go to a single remote Durable Object instance.
const stub = env.MY_DURABLE_OBJECT.getByName("foo");

// Call the `sayHello()` RPC method on the stub to invoke the method on
// the remote Durable Object instance
// the remote Durable Object instance.
const greeting = await stub.sayHello("world");

return new Response(greeting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ class Default(WorkerEntrypoint):
* @returns {Promise<Response>} The response to be sent back to the client
"""
async def fetch(self, request):
# Create a `DurableObjectId` for an instance of the `MyDurableObject`
# class named "foo". Requests from all Workers to the instance named
# "foo" will go to a single globally unique Durable Object instance.
id = self.env.MY_DURABLE_OBJECT.idFromName("foo")
# Create a stub to open a communication channel with the Durable Object
# instance named "foo".
#
# Requests from all Workers to the Durable Object instance named "foo"
# will go to a single remote Durable Object instance.
stub = self.env.MY_DURABLE_OBJECT.getByName("foo")

# Create a stub to open a communication channel with the Durable
# Object instance.
stub = self.env.MY_DURABLE_OBJECT.get(id)

# Call the `say_hello()` RPC method on the stub to invoke the method on
# the remote Durable Object instance
# Call the `say_hello()` RPC method on the stub to invoke the method on
# the remote Durable Object instance.
greeting = await stub.say_hello("world")

return Response(greeting)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ export default {
* @returns The response to be sent back to the client
*/
async fetch(request, env, ctx): Promise<Response> {
// Create a `DurableObjectId` for an instance of the `MyDurableObject`
// class named "foo". Requests from all Workers to the instance named
// "foo" will go to a single globally unique Durable Object instance.
const id: DurableObjectId = env.MY_DURABLE_OBJECT.idFromName("foo");

// Create a stub to open a communication channel with the Durable
// Object instance.
const stub = env.MY_DURABLE_OBJECT.get(id);
// Create a stub to open a communication channel with the Durable Object
// instance named "foo".
//
// Requests from all Workers to the Durable Object instance named "foo"
// will go to a single remote Durable Object instance.
const stub = env.MY_DURABLE_OBJECT.getByName("foo");

// Call the `sayHello()` RPC method on the stub to invoke the method on
// the remote Durable Object instance
// the remote Durable Object instance.
const greeting = await stub.sayHello("world");

return new Response(greeting);
Expand Down
Loading