-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add axios transformRequest and transformResponse
- Loading branch information
1 parent
570a628
commit 74cc0fa
Showing
5 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { parse, stringify } = require('./jsonb.cjs') | ||
|
||
module.exports.transformRequest = function transformRequest(data, headers) { | ||
if (data.constructor === Object) { | ||
headers['Content-Type'] = 'application/json;charset=utf-8' | ||
return stringify(data) | ||
} | ||
return data; | ||
} | ||
|
||
module.exports.transformResponse = function transformResponse(data) { | ||
return typeof data === 'string' ? parse(data) : data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function transformRequest( | ||
data: any, | ||
headers: Record<string, string>, | ||
): any | ||
export function transformResponse(data: any): any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { parse, stringify } from './jsonb.js' | ||
export function transformRequest(data, headers) { | ||
if (data.constructor === Object) { | ||
headers['Content-Type'] = 'application/json;charset=utf-8' | ||
return stringify(data) | ||
} | ||
return data | ||
} | ||
|
||
export function transformResponse(data) { | ||
return typeof data === 'string' ? parse(data) : data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters