Reason Behind CallAnAPI Allowing Only One URL #3208
|
I’m trying to understand the design choice behind CallAnAPI allowing only a single URL. When I need to work with multiple endpoints, I have to create separate actors for each. Could you clarify the reason for this limitation? |
Replies: 1 comment
|
Thanks for raising this - it's a good question and comes up quite often when people start working with multiple APIs in the same test suite.
That said, you're not locked into that base URL. As described in the docs, you can still send requests to any other endpoint by specifying the full URL explicitly. Here's the example for reference: import { actorCalled } from '@serenity-js/core'
import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
import { Ensure, equals } from '@serenity-js/assertions'
await actorCalled('Apisitt')
.whoCan(
CallAnApi.at(baseURL)
)
.attemptsTo(
Send.a(GetRequest.to(resourcePath)),
Ensure.that(LastResponse.status(), equals(200)),
)What happens depends on how resourcePath is defined:
Here’s how that plays out in practice:
So in short: the base URL is there for convenience, not a limitation. When you need to call a different service, just pass a full URL and Serenity/JS will use it as-is. |
Thanks for raising this - it's a good question and comes up quite often when people start working with multiple APIs in the same test suite.
CallAnApiis intentionally configured with a default base URL to reduce configuration noise and repetition across your tests. In most scenarios, you're interacting with a single API, so having a shared base URL keeps your test code concise and easier to maintain.That said, you're not locked into that base URL.
As described in the docs, you can still send requests to any other endpoint by specifying the full URL explicitly. Here's the example for reference: