Skip to main content

RxJS API Reference

Welcome to the comprehensive RxJS API reference. This documentation covers all creation operators, transformation operators, filtering operators, and utility functions available in RxJS.

What is RxJS?

RxJS (Reactive Extensions for JavaScript) is a library for reactive programming using Observables, making it easier to compose asynchronous or callback-based code. It provides powerful operators for transforming, filtering, and combining streams of data.

Core Concepts

Observable

An Observable is a collection of future values or events. It’s lazy - values are only computed when you subscribe to them.
import { Observable } from 'rxjs';

const observable = new Observable(subscriber => {
  subscriber.next(1);
  subscriber.next(2);
  subscriber.complete();
});

Observer

An Observer is a collection of callbacks that knows how to listen to values delivered by the Observable.
const observer = {
  next: x => console.log('Observer got a next value: ' + x),
  error: err => console.error('Observer got an error: ' + err),
  complete: () => console.log('Observer got a complete notification')
};

Subscription

A Subscription represents the execution of an Observable and is primarily used for cancelling execution.
const subscription = observable.subscribe(observer);
// Later...
subscription.unsubscribe();

Creation Operators

Creation operators are functions that create Observables from various sources. These are the building blocks for creating Observable streams.

Common Creation Operators

of

Emits a sequence of values synchronously

from

Converts arrays, promises, or iterables to Observables

interval

Emits sequential numbers at specified intervals

timer

Emits after a delay, optionally repeating

fromEvent

Creates Observable from DOM or Node.js events

ajax

Creates Observable for AJAX requests

combineLatest

Combines latest values from multiple Observables

merge

Merges multiple Observables into one

All Creation Operators

  • ajax - Create Observable for AJAX requests
  • bindCallback - Convert callback API to Observable
  • bindNodeCallback - Convert Node.js callback to Observable
  • combineLatest - Combine latest values from Observables
  • concat - Concatenate Observables sequentially
  • defer - Create Observable lazily on subscription
  • forkJoin - Wait for all Observables to complete
  • from - Convert various sources to Observable
  • fromEvent - Create from DOM or event emitter
  • fromEventPattern - Create from arbitrary event API
  • generate - Generate values using a loop
  • interval - Emit numbers periodically
  • merge - Merge multiple Observables concurrently
  • of - Emit values as a sequence
  • range - Emit a range of numbers
  • throwError - Create Observable that errors
  • timer - Emit after delay
  • zip - Combine Observables by index

Quick Start Example

import { of } from 'rxjs';
import { map } from 'rxjs/operators';

const source$ = of(1, 2, 3, 4, 5);
const result$ = source$.pipe(
  map(x => x * 2)
);

result$.subscribe(x => console.log(x));
// Output: 2, 4, 6, 8, 10

Type Safety

RxJS is written in TypeScript and provides full type safety for all operators.
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

// Type is Observable<number>
const numbers$: Observable<number> = of(1, 2, 3);

// Type is Observable<string>
const strings$ = numbers$.pipe(
  map(n => n.toString())
);

Next Steps

Explore Creation Operators

Learn about all the ways to create Observables
This API reference is based on RxJS v7+. Some operators may have different signatures in earlier versions.