Configuration

The client's behavior is controlled by a RMPClientConfig object. Build one with createConfig() and pass it to the constructor. If you don't pass config, the client uses sensible defaults.

Default Usage #

import { RMPClient } from "ratemyprofessors-client";
const client = new RMPClient();

Custom Configuration #

import { RMPClient, createConfig } from "ratemyprofessors-client";

const client = new RMPClient(
  createConfig({ max_retries: 5, timeout_seconds: 15 })
);

createConfig #

createConfig(overrides?: Partial<RMPClientConfig>): RMPClientConfig

Builds a full config by merging your overrides onto the defaults.

RMPClientConfig #

FieldTypeDefaultDescription
base_urlstring"https://www.ratemyprofessors.com/graphql"GraphQL endpoint URL
timeout_secondsnumber10Request timeout in seconds
max_retriesnumber3Maximum retries on 5xx or network errors
user_agentstringFirefox UA stringUser-Agent header sent with every request
default_headersRecord<string, string>User-Agent + Accept-LanguageHeaders merged into every request

Rate Limiting #

The client uses a token bucket algorithm fixed at 60 requests per minute. Tokens replenish continuously at 1 per second. Each request consumes one token; if none are available the request blocks until one becomes available. This limit is not configurable.

Retry Behaviour #

SituationRetried?
Network error (timeout, connection reset)Yes
5xx server errorYes
4xx client error (400, 401, 403, 404)No — throws HttpError immediately
429 Too Many RequestsYes — exponential back-off, up to max_retries times
GraphQL errors in a 200 responseNo — throws RMPAPIError immediately

Retries #

Failed requests (5xx or network errors) are retried with exponential backoff. If all retries fail, a RetryError is thrown.

const client = new RMPClient(createConfig({ max_retries: 5 }));

Timeouts #

Each request has a timeout of timeout_seconds. If exceeded, the request is aborted and may be retried.

const client = new RMPClient(createConfig({ timeout_seconds: 30 }));