remy / jsonbin

A personal JSON store as a RESTful service
https://jsonbin.org
395 stars 26 forks source link

API always get null after post data to "/me". #23

Closed jeffwu85182 closed 7 years ago

jeffwu85182 commented 7 years ago

Hi,

I had a problem. I ain't sure it's a bug or not. Here is what I did to cause the problem.

I post the following Json data to https://jsonbin.org/me.

[
  {
    "value": "Hello",
    "done": false
  },
  {
    "value": "Hello2",
    "done": false
  }
]

And then I POST data to another API I created and had 201 state returned. But when I try to GET data from the API I created, it will always return null.

And then, I post the following JSON to https://jsonbin.org/me again. Now APIs I created back to work.

{
  "urls": [
    "https://jsonbin.org/_/help",
    "https://jsonbin.org/_/me",
    "https://jsonbin.org/_/logout"
  ],
  "gettingStarted": "check out the *help*, and try 'curl https://jsonbin.org/jeffwu85182 -H \"authorization: token <myToken>\"'"
}

I think /me should not be modified and should not accept POST or DELETE operations.

Thanks for your time.

remy commented 7 years ago

I'm sorry, I don't really follow what you're saying. Can you give me a sequence of curl commands (obviously leaving you your token) so I can see if I can replicate what you're seeing?

On Wed, 26 Apr 2017, 07:33 Jeff Wu, notifications@github.com wrote:

Hi,

I had a problem. I ain't sure it's a bug or not. Here is what I did to cause the problem.

I post the following Json data to https://jsonbin.org/me.

[ { "value": "Hello", "done": false }, { "value": "Hello2", "done": false } ]

And then I POST data to another API I created and had 201 state returned. But when I try to GET data from the API I created, it will always return null.

And then, I post the following JSON to https://jsonbin.org/me again. Now APIs I created back to work.

{ "urls": [ "https://jsonbin.org/_/help", "https://jsonbin.org/_/me", "https://jsonbin.org/_/logout" ], "gettingStarted": "check out the help, and try 'curl https://jsonbin.org/jeffwu85182 -H \"authorization: token \"'" }

I think /me should not be modified and should not accept POST or DELETE operations.

Thanks for your time.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/remy/jsonbin/issues/23, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA1hASAg6QRtdw3xnguSDlZXfLJoNqmks5rzuVQgaJpZM4NIbFB .

remy commented 7 years ago

Or are you just asking this?

I think /me should not be modified and should not accept POST or DELETE operations.

jeffwu85182 commented 7 years ago

OK, the step is:

  1. POST the following JSON to https://jsonbin.org/me => 201 (Created)
    [{
    "value": "Hello",
    "done": false
    },
    {
    "value": "Hello2",
    "done": false
    }]
  2. GET from https://jsonbin.org/me => 200 (OK)
  3. POST data like step 1 to https://jsonbin.org/me/demo0419 => 201 (Created)
  4. GET from https://jsonbin.org/me/demo0419 => 404 (Not Found) ============================ that's the problem so far And I referred the new account which using GET data from https://jsonbin.org/me, got the following JSON:
    {
    "urls": [
    "https://jsonbin.org/_/help",
    "https://jsonbin.org/_/me",
    "https://jsonbin.org/_/logout"
    ],
    "gettingStarted": "check out the *help*, and try 'curl https://jsonbin.org/<my account ID> -H \"authorization: token <my token>\"'"
    }
  5. POST JSON to https://jsonbin.org/me => 201 (Created) Retry step 3 and 4, then work correctly.
remy commented 7 years ago

Can I assume you're doing this with an active account from the first step?

I'm sorry, I'm still having trouble visualising what's going on here (I'm about to take my kids to school, so I'll run some code when I'm back), but I think you're saying that step 4 gives a 404 which is definitely a bug. But I wonder if it tried to coarse an array into an object and broke (but this would be straightforward to test using the text test language).

But I'm not sure how you're able to get it working correctly in your step 5. It's that part I'm not quite sure how you've managed to get to. Did you reset your account?

jeffwu85182 commented 7 years ago

Nope, I just revoke my token several times. I'm not sure why step 5 can fix the problem, too. Should I leave my token? btw, I am testing the API by Postman.

remy commented 7 years ago

After you revoke your token, are you resetting your data, or is it actually coming back from GET https://jsonbin.org/me as the initial content?

jeffwu85182 commented 7 years ago

I don't think so. After revoke my token, I didn't reset my data. It's still not working correctly to GET custom API.

jeffwu85182 commented 7 years ago

Here is curl command step:

Step 1. POST JSON data to https://jsonbin.org/me

curl -X POST \
  https://jsonbin.org/me \
  -H 'authorization: token a4871c65-05ca-46ea-b066-4ebe6c28fb75' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: 67222c0f-bd91-72b9-6500-e2c9e4584927' \
  -d '[{
  "value": "Hello",
  "done": false
},
{
  "value": "Hello2",
  "done": false
}]'

Step 2. GET JSON data from https://jsonbin.org/me

curl -X GET \
  https://jsonbin.org/me \
  -H 'authorization: token a4871c65-05ca-46ea-b066-4ebe6c28fb75' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: 3ce9efb6-d89c-7b53-0fbd-d48756f6a31e' 

It's work correctly so far. Then try to POST JSON data to https://jsonbin.org/me/demo0419

Step 3. POST JSON data to https://jsonbin.org/me/demo0419 => 201 ( Created )

curl -X POST \
  https://jsonbin.org/me/demo0419 \
  -H 'authorization: token a4871c65-05ca-46ea-b066-4ebe6c28fb75' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: 54a7f771-ba3d-0c37-5a73-35425b7b4e81' \
  -d '[{
  "value": "Hello",
  "done": false
},
{
  "value": "Hello2",
  "done": false
}]'

Step 4. GET JSON data from https://jsonbin.org/me/demo0419 => 404 ( Not Found )

curl -X GET \
  https://jsonbin.org/me/demo0419 \
  -H 'authorization: token a4871c65-05ca-46ea-b066-4ebe6c28fb75' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: a6396713-e59b-3eb1-60b8-1133ad2e0fb1'

Step 5. POST JSON data to https://jsonbin.org/me

curl -X POST \
  https://jsonbin.org/me \
  -H 'authorization: token a4871c65-05ca-46ea-b066-4ebe6c28fb75' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: 47e68e54-c2dd-f17c-1efa-f778801d6815' \
  -d '{
  "urls": [
    "https://jsonbin.org/_/help",
    "https://jsonbin.org/_/me",
    "https://jsonbin.org/_/logout"
  ],
  "gettingStarted": "check out the *help*, and try '\''curl https://jsonbin.org/jeffwu85182 -H \"authorization: token a4871c65-05ca-46ea-b066-4ebe6c28fb75\"'\''"
}'

Then retry Step 3 & 4, it's working correctly.

remy commented 7 years ago

Cheers. I'll use that to automate a test to see if I can work out what's going on in the morning.

My gut feeling is that the first time around it's some kind of "uncoearsable" array but after you do a manual reset you're then able to add the demo property.

On Wed, 26 Apr 2017, 17:07 Jeff Wu, notifications@github.com wrote:

Here is curl command step:

Step 1. POST JSON data to https://jsonbin.org/me

curl -X POST \ https://jsonbin.org/me \ -H 'authorization: token a4871c65-05ca-46ea-b066-4ebe6c28fb75' \ -H 'cache-control: no-cache' \ -H 'content-type: application/json' \ -H 'postman-token: 67222c0f-bd91-72b9-6500-e2c9e4584927' \ -d '[{ "value": "Hello", "done": false }, { "value": "Hello2", "done": false }]'

Step 2. GET JSON data from https://jsonbin.org/me

curl -X GET \ https://jsonbin.org/me \ -H 'authorization: token a4871c65-05ca-46ea-b066-4ebe6c28fb75' \ -H 'cache-control: no-cache' \ -H 'content-type: application/json' \ -H 'postman-token: 3ce9efb6-d89c-7b53-0fbd-d48756f6a31e'

It's work correctly so far. Then try to POST JSON data to https://jsonbin.org/me/demo0419

Step 3. POST JSON data to https://jsonbin.org/me/demo0419 => 201 ( Created )

curl -X POST \ https://jsonbin.org/me/demo0419 \ -H 'authorization: token a4871c65-05ca-46ea-b066-4ebe6c28fb75' \ -H 'cache-control: no-cache' \ -H 'content-type: application/json' \ -H 'postman-token: 54a7f771-ba3d-0c37-5a73-35425b7b4e81' \ -d '[{ "value": "Hello", "done": false }, { "value": "Hello2", "done": false }]'

Step 4. GET JSON data from https://jsonbin.org/me/demo0419 => 404 ( Not Found )

curl -X GET \ https://jsonbin.org/me/demo0419 \ -H 'authorization: token a4871c65-05ca-46ea-b066-4ebe6c28fb75' \ -H 'cache-control: no-cache' \ -H 'content-type: application/json' \ -H 'postman-token: a6396713-e59b-3eb1-60b8-1133ad2e0fb1'

Step 5. POST JSON data to https://jsonbin.org/me

curl -X POST \ https://jsonbin.org/me \ -H 'authorization: token a4871c65-05ca-46ea-b066-4ebe6c28fb75' \ -H 'cache-control: no-cache' \ -H 'content-type: application/json' \ -H 'postman-token: 47e68e54-c2dd-f17c-1efa-f778801d6815' \ -d '{ "urls": [ "https://jsonbin.org/_/help", "https://jsonbin.org/_/me", "https://jsonbin.org/_/logout" ], "gettingStarted": "check out the help, and try '\''curl https://jsonbin.org/jeffwu85182 -H \"authorization: token a4871c65-05ca-46ea-b066-4ebe6c28fb75\"'\''" }'

Then retry Step 3 & 4, it's working correctly.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/remy/jsonbin/issues/23#issuecomment-297460703, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA1hLMKUtiTUj_kpuz5XhNOU-ffJ_uIks5rz2vDgaJpZM4NIbFB .

remy commented 7 years ago

Fixed. Took some magic to get it working, and I've noticed it changes the concept of patching once you coerce the array to an object (but setting a property on it), but I think that's valid and okay.