Service Binding call resulting in TypeError
Hello, I'm currently working on implementing Service Bindings but I'm running into the following error when calling the
fetch()
of the service binding and passing on a string: TypeError: Fetch API cannot load: <MY-STRING>
The Env interface:
The binding in the wrangler.toml:
The service binding fetch call:
9 Replies
You need to give it a valid url
ex.
https://example.invalid/MY-STRING
It doesn't matter what it is, just needs to be an absolute url it can load. Can be completely invalid hostSo the format must be an URL even though it's arbitrary data I'm passing on?
And then I strip the dummy URL in the other worker receiving the request?
the data type has to be a string, the format has to be a valid absolute url, because of the fetch interface
with service bindings you should be able to pass data via the cf object on request/fetch as well, anything you set should just be passed on, can be useful
but yea as for how you handle it it's up to. You could just ignore the host and parse the path on the other worker if your goal is to pass information
var newURL = new URL(request.url)
var path = newURL.pathname;
How do I access the cf object or is there any documentation about that?
it's just an object you can set in fetch or new requests
For example, you can even pass the entire incoming request object and it'll keep the cf properties the same
Request ยท Cloudflare Workers docs
Interface that represents an HTTP request.
Yeah just noticed when the type documentation ๐ And the same object is readable in the Request object of destination worker, isn't it?
Thanks! Will look into that ๐
yea, it just gets passed on as is through a service binding
Alright, thanks for your help ๐