Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ots
hypha
Commits
d88b3329
Unverified
Commit
d88b3329
authored
6 years ago
by
Tomasz Knapik
Browse files
Options
Downloads
Patches
Plain Diff
Move decamelizing to the middleware
parent
0a30734d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
opentech/static_src/src/app/src/api/utils.js
+1
-9
1 addition, 9 deletions
opentech/static_src/src/app/src/api/utils.js
opentech/static_src/src/app/src/redux/middleware/api.js
+13
-1
13 additions, 1 deletion
opentech/static_src/src/app/src/redux/middleware/api.js
with
14 additions
and
10 deletions
opentech/static_src/src/app/src/api/utils.js
+
1
−
9
View file @
d88b3329
import
{
decamelizeKeys
}
from
'
humps
'
;
import
Cookies
from
'
js-cookie
'
;
import
Cookies
from
'
js-cookie
'
;
const
getBaseUrl
=
()
=>
{
const
getBaseUrl
=
()
=>
{
return
process
.
env
.
API_BASE_URL
;
return
process
.
env
.
API_BASE_URL
;
};
};
export
function
apiFetch
({
path
,
method
=
'
GET
'
,
params
=
{},
options
=
{}
,
decamelizeJSON
=
true
})
{
export
function
apiFetch
({
path
,
method
=
'
GET
'
,
params
=
{},
options
=
{}})
{
const
url
=
new
URL
(
getBaseUrl
());
const
url
=
new
URL
(
getBaseUrl
());
url
.
pathname
=
path
;
url
.
pathname
=
path
;
...
@@ -23,13 +22,6 @@ export function apiFetch({path, method = 'GET', params = {}, options = {}, decam
...
@@ -23,13 +22,6 @@ export function apiFetch({path, method = 'GET', params = {}, options = {}, decam
};
};
}
}
if
(
decamelizeJSON
===
true
&&
options
.
body
!==
undefined
)
{
options
=
{
...
options
,
body
:
JSON
.
stringify
(
decamelizeKeys
(
options
.
body
))
}
}
return
fetch
(
url
,
{
return
fetch
(
url
,
{
...
options
,
...
options
,
headers
:
{
headers
:
{
...
...
This diff is collapsed.
Click to expand it.
opentech/static_src/src/app/src/redux/middleware/api.js
+
13
−
1
View file @
d88b3329
import
{
camelizeKeys
}
from
'
humps
'
import
{
camelizeKeys
,
decamelizeKeys
}
from
'
humps
'
import
{
apiFetch
}
from
'
@api/utils
'
import
{
apiFetch
}
from
'
@api/utils
'
const
callApi
=
(
endpoint
)
=>
{
const
callApi
=
(
endpoint
)
=>
{
// If body is an object, decamelize the keys.
const
{
options
}
=
endpoint
;
if
(
options
!==
undefined
&&
typeof
options
.
body
===
'
object
'
)
{
endpoint
=
{
...
endpoint
,
options
:
{
...
options
,
body
:
JSON
.
stringify
(
decamelizeKeys
(
options
.
body
))
}
}
}
return
apiFetch
(
endpoint
)
return
apiFetch
(
endpoint
)
.
then
(
response
=>
.
then
(
response
=>
response
.
json
().
then
(
json
=>
{
response
.
json
().
then
(
json
=>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment