Skip to content

Commit

Permalink
Merge pull request #76 from Polymarket/feat/http-headers
Browse files Browse the repository at this point in the history
feat/adding http headers to client requests
  • Loading branch information
poly-rodr authored Feb 15, 2023
2 parents b8285e2 + b1d7e7f commit e692b0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@polymarket/clob-client",
"description": "Typescript client for Polymarket's CLOB",
"version": "1.2.1",
"version": "1.2.2",
"contributors": [
{
"name": "Jonathan Amenechi",
Expand Down
16 changes: 16 additions & 0 deletions src/http-helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import axios, { Method } from "axios";
import { FilterParams, TradeNotificationParams, TradeParams } from "src/types";
import { OpenOrderParams } from "../types";
import { name, version } from "./../../package.json";

export const GET = "GET";
export const POST = "POST";
export const DELETE = "DELETE";
export const PUT = "PUT";

const overloadHeaders = (method: Method, headers?: Record<string, string | number | boolean>) => {
if (!headers || typeof headers === undefined) {
headers = {};
}
headers!["User-Agent"] = `${name}@${version}`;
headers!["Accept"] = "*/*";
headers!["Connection"] = "keep-alive";
headers!["Content-Type"] = "application/json";

if (method === GET) {
headers!["Accept-Encoding"] = "gzip";
}
};

export const request = async (
endpoint: string,
method: Method,
Expand All @@ -15,6 +30,7 @@ export const request = async (
params?: any,
): Promise<any> => {
try {
overloadHeaders(method, headers);
const response = await axios({ method, url: endpoint, headers, data, params });
return response;
} catch (err) {
Expand Down

0 comments on commit e692b0d

Please sign in to comment.