Skip to main content
Version: Next

ActorServerClient

Client for the server interface of a specific Actor.

Provides methods to work with the web server of a Server Actor, such as sending it requests or getting its OpenAPI specification. Get an instance with ActorClient.server.

Hierarchy

  • ResourceClient
    • ActorServerClient
const client = new ApifyClient({ token: 'my-token' });
const actorServerClient = client.actor('username/actor-name').server();

const response = await actorServerClient.request('/search', { params: { q: 'apify' } });
console.log(response.data);

Index

Properties

inheritedapifyClient

apifyClient: ApifyClient

inheritedbaseUrl

baseUrl: string

inheritedhttpClient

httpClient: HttpClient

optionalinheritedid

id?: string

optionalinheritedparams

params?: Record<string, unknown>

inheritedpublicBaseUrl

publicBaseUrl: string

Added in 2.17.0

inheritedresourcePath

resourcePath: string

optionalinheritedsafeId

safeId?: string

inheritedurl

url: string

Methods

getOpenApiSpec

  • getOpenApiSpec(options): Promise<undefined | Record<string, unknown>>
  • Returns the OpenAPI specification of the Actor's server.

    The specification is the web server schema from the Actor's definition, taken from the build that serves the server interface: the build set in actorStandby.build, or latest if none is set. Use it to generate an HTTP client for the server, and point that client at the URL returned by getUrl.


    Parameters

    Returns Promise<undefined | Record<string, unknown>>

    The OpenAPI specification of the Actor's server, or undefined if the Actor's definition doesn't include one

    Throws - When the Actor is not a Server Actor, or the build that serves its server interface doesn't exist.

    Throws - When the Actor does not exist.

getUrl

  • getUrl(options): Promise<string>
  • Returns the URL of the Actor's server.

    The URL is the Actor's standbyUrl, fetched from the API by the first call of this method or getOpenApiSpec and reused by later calls on this client. Use it to call the server with another HTTP client, for example one generated from the server's OpenAPI specification.


    Parameters

    Returns Promise<string>

    The URL of the Actor's server

    Throws - When the Actor is not a Server Actor.

    Throws - When the Actor does not exist.

request

  • Sends an HTTP request to the Actor's server.

    The request goes to the URL returned by getUrl and carries the client's token in the X-Apify-Authorization header, which the platform consumes, so it never reaches the Actor's code. Headers you pass, Authorization included, reach the Actor's server as they are. The first request to an idle Actor waits for the platform to start a server run, which is why the timeout defaults to 'long'.

    The method resolves to any response of the server, error statuses included. A rate-limit (429) or Service Unavailable (503) response is retried with the client's retry settings, and the last one is returned once the retries run out. The Actor's code can return these statuses too, and then it gets the request again. A redirect is returned as it is, since following it would send the token to a host the Actor's code picked. A browser follows redirects itself, though, so there the token goes with a redirect. Request bodies are sent uncompressed unless compression is set, since the Actor's server may not decode a compressed body.


    Parameters

    • optionalpath: string

      The path on the Actor's server, for example /search. It is always resolved against the server URL, so the request, and the token with it, can't be sent to another host. Pass the query in params. A fragment (#...) is dropped, since it's never sent to the server.

    • optionaloptions: ActorServerRequestOptions & { responseType?: parsed }

      Request options

    Returns Promise<ApifyResponse<T>>

    The response of the Actor's server, with the body in the form responseType asks for. An error response whose body doesn't parse as its content type comes with the raw bytes in data.

    Throws - When the Actor is not a Server Actor.

    Throws - When a success response's body doesn't parse as its content type, with responseType: 'parsed'.

    Throws - When the Actor does not exist.