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 #
| 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 |
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 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 #
| Situation | Retried? |
|---|---|
| Network error (timeout, connection reset) | Yes |
| 5xx server error | Yes |
| 4xx client error (400, 401, 403, 404) | No — throws HttpError immediately |
| 429 Too Many Requests | Yes — exponential back-off, up to max_retries times |
GraphQL errors in a 200 response | No — 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 }));