Skip to content

Commit d854bab

Browse files
authored
Merge pull request #122 from tlconnor/fixAcceptHeader
Default Accept and Content-Type headers to application/vnd.api+json
2 parents 2196041 + 1d0af3c commit d854bab

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ export class JSORMBase {
671671
static fetchOptions(): RequestInit {
672672
const options = {
673673
headers: {
674-
Accept: "application/json",
675-
["Content-Type"]: "application/json"
674+
Accept: "application/vnd.api+json",
675+
["Content-Type"]: "application/vnd.api+json"
676676
} as any
677677
}
678678

@@ -941,4 +941,4 @@ export const isModelInstance = (arg: any): arg is JSORMBase => {
941941
return false
942942
}
943943
return isModelClass(arg.constructor.currentClass)
944-
}
944+
}

test/integration/fetch-middleware.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ describe("fetch middleware", () => {
152152
expect(before.url).to.eq("http://example.com/api/v1/authors")
153153
expect(before.options).to.deep.eq({
154154
headers: {
155-
Accept: "application/json",
156-
"Content-Type": "application/json",
155+
Accept: "application/vnd.api+json",
156+
"Content-Type": "application/vnd.api+json",
157157
"CUSTOM-HEADER": "whatever"
158158
},
159159
method: "GET"
@@ -309,9 +309,9 @@ describe("fetch middleware", () => {
309309
expect(before.url).to.eq("http://example.com/api/v1/authors")
310310
expect(before.options).to.deep.eq({
311311
headers: {
312-
Accept: "application/json",
312+
Accept: "application/vnd.api+json",
313313
"CUSTOM-HEADER": "whatever",
314-
"Content-Type": "application/json"
314+
"Content-Type": "application/vnd.api+json"
315315
},
316316
body: JSON.stringify({ data: { type: "authors" } }),
317317
method: "POST"

test/unit/model.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,8 +1485,8 @@ describe("Model", () => {
14851485

14861486
it("includes the content headers", () => {
14871487
const headers: any = Author.fetchOptions().headers
1488-
expect(headers.Accept).to.eq("application/json")
1489-
expect(headers["Content-Type"]).to.eq("application/json")
1488+
expect(headers.Accept).to.eq("application/vnd.api+json")
1489+
expect(headers["Content-Type"]).to.eq("application/vnd.api+json")
14901490
})
14911491
})
14921492
})

0 commit comments

Comments
 (0)