Skip to content

Instantly share code, notes, and snippets.

@bennadel
bennadel / api-client.js
Created January 9, 2022 14:18
Building An API Client With The fetch() API In JavaScript
// Regular expression patterns for testing content-type response headers.
var RE_CONTENT_TYPE_JSON = new RegExp( "^application/(x-)?json", "i" );
var RE_CONTENT_TYPE_TEXT = new RegExp( "^text/", "i" );
// Static strings.
var UNEXPECTED_ERROR_MESSAGE = "An unexpected error occurred while processing your request.";
export class ApiClient {
/**
* I initialize the API client.