Skip to content

Add AbortSignal support to HTTP requests #53

@grantfox-oss

Description

@grantfox-oss

Summary

Allow callers to cancel in-flight SDK requests using an external AbortSignal. This improves integration with browser UI lifecycles, server request handlers, and applications that need user-driven cancellation.

Current Behaviour

HttpClient creates its own AbortController for timeout handling, but HttpRequestOptions does not accept an external signal. Consumers cannot cancel requests when components unmount, route handlers are aborted, or a newer request supersedes an older one.

Expected Behaviour

SDK request options should accept an optional AbortSignal and abort the underlying fetch when either the timeout or the external signal fires.

Suggested Implementation

Add signal?: AbortSignal to HttpRequestOptions. Update HttpClient.request to compose timeout cancellation with external cancellation. Ensure timeout errors and user-initiated aborts can be distinguished where possible.

Files or Areas Likely Affected

  • src/http/http.types.ts
  • src/http/httpClient.ts
  • src/errors/errorCodes.ts
  • tests/httpClient.test.ts
  • docs/sdk-guide.md

Acceptance Criteria

  • HttpRequestOptions accepts an optional AbortSignal
  • External aborts cancel the underlying fetch
  • Timeout behaviour continues to work as before
  • Already-aborted signals fail safely without unnecessary work
  • Tests cover timeout, external abort, and successful request paths
  • Documentation includes a short cancellation example

Additional Notes

This should complement the existing timeout implementation rather than replacing it.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions