Ghost icon indicating copy to clipboard operation
Ghost copied to clipboard

Bug: About new restful API

Open Lemon7Frank opened this issue 10 years ago • 4 comments

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

Lemon7Frank avatar Dec 18 '15 04:12 Lemon7Frank

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.

chripf avatar Dec 18 '15 05:12 chripf

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

Lemon7Frank avatar Dec 18 '15 08:12 Lemon7Frank

Confirmed, I'm working on a fix.

halfdan avatar Dec 18 '15 09:12 halfdan

This will be closed automatically when the fix is merged.

ErisDS avatar Dec 19 '15 09:12 ErisDS