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({ rate_limit_per_minute: 30, max_retries: 5, timeout_seconds: 15 })
);
createConfig #
createConfig(overrides?: Partial<RMPClientConfig>): RMPClientConfig
Builds a full config by merging your overrides onto the defaults.
RMPClientConfig #
| Field | Type | Default | Description |
|---|---|---|---|
base_url | string | "https://www.ratemyprofessors.com/graphql" | GraphQL endpoint URL |
timeout_seconds | number | 10 | Request timeout in seconds |
max_retries | number | 3 | Maximum retries on 5xx or network errors |
rate_limit_per_minute | number | 60 | Maximum requests per minute (token bucket) |
user_agent | string | Firefox UA string | User-Agent header sent with every request |
default_headers | Record<string, string> | User-Agent + Accept-Language | Headers merged into every request |
Rate Limiting #
The client uses a token bucket algorithm. The bucket holds up to rate_limit_per_minute tokens and refills continuously. Each request consumes one token.
const client = new RMPClient(createConfig({ rate_limit_per_minute: 10 }));
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 }));