1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-12-12 05:38:55 +09:00

[Client] Use JSON for API requests

This commit is contained in:
syuilo 2017-02-12 02:19:19 +09:00
parent 680f9a0b5c
commit 7791dd5471
2 changed files with 6 additions and 16 deletions

View File

@ -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) {

View File

@ -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