Skip to content

Commit

Permalink
generalize headers
Browse files Browse the repository at this point in the history
  • Loading branch information
F-Node-Karlsruhe committed Jan 24, 2023
1 parent 8bc43d4 commit db956c7
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions api/src/services/fetch/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@

import parseLink from 'parse-link-header';

const JSON_HEADERS = {
'Accept': 'application/json'
const HEADERS = {
'Accept': 'application/ld+json, application/json'
}

const JSONLD_HEADERS = {
'Accept': 'application/ld+json'
}

export async function fetch_jsonld(url: string): Promise<object> {

const response = await fetch(url, { method: 'GET', headers: JSONLD_HEADERS});
const response = await fetch(url, { method: 'GET', headers: HEADERS});

const contentType = response.headers.get("content-type");

Expand All @@ -27,7 +24,7 @@ export async function fetch_jsonld(url: string): Promise<object> {

if (link && link.alternate && link.alternate.rel == 'alternate' && link.alternate.type == 'application/ld+json') {

const linkResponse = await fetch(url + link.alternate.url, { method: 'GET', headers: JSONLD_HEADERS});
const linkResponse = await fetch(url + link.alternate.url, { method: 'GET', headers: HEADERS});

return await linkResponse.json();

Expand All @@ -40,7 +37,7 @@ export async function fetch_jsonld(url: string): Promise<object> {

export async function fetch_json(url: string): Promise<object> {

const response = await fetch(url, { method: 'GET', headers: JSON_HEADERS});
const response = await fetch(url, { method: 'GET', headers: HEADERS});

return await response.json();

Expand Down

0 comments on commit db956c7

Please sign in to comment.