[Client] Use JSON for API requests
This commit is contained in:
parent
680f9a0b5c
commit
7791dd5471
|
@ -111,10 +111,9 @@ function fetchme(token, cb) {
|
||||||
// Fetch user
|
// Fetch user
|
||||||
fetch(CONFIG.api.url + "/i", {
|
fetch(CONFIG.api.url + "/i", {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: JSON.stringify({
|
||||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
i: token
|
||||||
},
|
})
|
||||||
body: "i=" + token
|
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
// When failed to authenticate user
|
// When failed to authenticate user
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
|
|
|
@ -8,7 +8,7 @@ net = riot.observable!
|
||||||
riot.mixin \net do
|
riot.mixin \net do
|
||||||
net: net
|
net: net
|
||||||
|
|
||||||
module.exports = (i, endpoint, data) ->
|
module.exports = (i, endpoint, data = {}) ->
|
||||||
if ++pending == 1
|
if ++pending == 1
|
||||||
spinner := document.create-element \div
|
spinner := document.create-element \div
|
||||||
..set-attribute \id \wait
|
..set-attribute \id \wait
|
||||||
|
@ -16,21 +16,12 @@ module.exports = (i, endpoint, data) ->
|
||||||
|
|
||||||
if i? and typeof i == \object then i = i.token
|
if i? and typeof i == \object then i = i.token
|
||||||
|
|
||||||
body = []
|
|
||||||
|
|
||||||
# append user token when signed in
|
# append user token when signed in
|
||||||
if i? then body.push "i=#i"
|
if i? then data.i = i
|
||||||
|
|
||||||
for k, v of data
|
|
||||||
if v != undefined
|
|
||||||
v = encodeURIComponent v
|
|
||||||
body.push "#k=#v"
|
|
||||||
|
|
||||||
opts =
|
opts =
|
||||||
method: \POST
|
method: \POST
|
||||||
headers:
|
body: JSON.stringify data
|
||||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
|
||||||
body: body.join \&
|
|
||||||
|
|
||||||
if endpoint == \signin
|
if endpoint == \signin
|
||||||
opts.credentials = \include
|
opts.credentials = \include
|
||||||
|
|
Loading…
Reference in a new issue