New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: About new restful API #6239

Closed
frankxin opened this Issue Dec 18, 2015 · 4 comments

Comments

Projects
None yet
4 participants
@frankxin

frankxin commented Dec 18, 2015

Issue Summary

ok , I try our new API , And I found there is some wrong when i use ajax twice continually

Steps to Reproduce

  1. This is my code
          ghost.init({
            clientId: "ghost-frontend",
            clientSecret: "8919dc8debd1"
          });

          jQuery(document).ready(function() {
            $.get(
              ghost.url.api('posts', {
                limit: 3
              })
            ).done(function(data) {
              var $result = $('#blog-posts');
              $.each(data.posts, function(i, post) {
                $result.append(
                  '<li>' + post.title + '</li>'
                );
              });
            });

            $.get(
              ghost.url.api('posts', {
                limit: 3
              })
            ).done(function(data) {
              var $result = $('#blog-posts');
              $.each(data.posts, function(i, post) {
                $result.append(
                  '<li>' + post.title + '</li>'
                );
              });
            });
          });
  1. The first request is right , and the second one return with an error
    image
    image

I think this is a bug because two times use one ghost api closure , In the ghost-url code
image , they use the same apiUrl variable ,and the second time I call ghost.url.api , they use the same variable.

Technical details

  • Ghost Version: master - latest commit: INSERT COMMIT REF
  • Client OS: mac
  • Browser: chrome latest
@chripf

This comment has been minimized.

chripf commented Dec 18, 2015

Have the same issue - tried doing a re-init before using the helper again, but this does not help.

Workaround

I actually found a way I can use it: doing an init at the beginning and then at each subsequential call (this is an infinite scroll implementation) I do not pass in any url part. Feels rather hack, though.

var postsUrl = ghost.url.api('posts',  {limit: postlimit});

... when calling the function:

postsUrl=ghost.url.api('', {limit: postlimit});

However, I agree this should work different - actually this makes any use of the helper impossible when trying to access different API-Endpoints in the same script.

@frankxin

This comment has been minimized.

frankxin commented Dec 18, 2015

@chripf Thank you for your reply . I totally agree with your method . And I think i can change the ghost-url.js for my project . Because in one context , if you want to get user after get posts , it would be wrong , the url will be like this //www.frankxin.com/ghost/api/v0.1/posts/users . So I want to check if this kind of API is by designed or it's a mistake.

@halfdan

This comment has been minimized.

Member

halfdan commented Dec 18, 2015

Confirmed, I'm working on a fix.

halfdan added a commit to halfdan/Ghost that referenced this issue Dec 18, 2015

Fix non-idempotent Ghost API helper
- Add test
- Don't override apiUrl

closes TryGhost#6239

halfdan added a commit to halfdan/Ghost that referenced this issue Dec 18, 2015

Fix non-idempotent Ghost API helper
- Add test
- Don't override apiUrl

closes TryGhost#6239

halfdan added a commit to halfdan/Ghost that referenced this issue Dec 18, 2015

Fix non-idempotent Ghost API helper
- Add test
- Don't override apiUrl

closes TryGhost#6239

@frankxin frankxin closed this Dec 19, 2015

@ErisDS ErisDS reopened this Dec 19, 2015

@ErisDS

This comment has been minimized.

Member

ErisDS commented Dec 19, 2015

This will be closed automatically when the fix is merged.

@ErisDS ErisDS closed this in #6240 Dec 20, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment