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

API does not respond to queries; tutorial cannot be followed #384

Closed
MichaelMarkieta opened this Issue Jan 16, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@MichaelMarkieta
Copy link

MichaelMarkieta commented Jan 16, 2018

Expected behavior

Requesting data on /1.0/library/books should return a collection of books

Actual behavior

Requesting data on /1.0/library/books returns a 404 Not Found

Steps to reproduce the problem

Followed the tutorial here: https://docs.dadi.tech/api#creating-an-api. I am able to retrieve an authentication token but not any API data. Note that I am using all of the defaults from the creation wizard, except:

  • http (80)
  • filestore (json)

Also, GET /api/collections

{
  "collections": [
    {
      "version": "vjoin",
      "database": "testdb",
      "name": "books",
      "slug": "books",
      "path": "/vjoin/testdb/books"
    },
    {
      "version": "vjoin",
      "database": "testdb",
      "name": "users",
      "slug": "users",
      "path": "/vjoin/testdb/users"
    },
    {
      "version": "vtest",
      "database": "testdb",
      "name": "test-schema",
      "slug": "test-schema",
      "path": "/vtest/testdb/test-schema"
    }
  ],
  "media": {
    "buckets": [
      "mediaStore"
    ],
    "defaultBucket": "mediaStore"
  }
}

Package details

Package version, operating system, etc

$ dadi api -v
2.1.4

$ node -v
v8.9.1

$ sw_vers -productVersion 
10.13.2
@jimlambie

This comment has been minimized.

Copy link
Member

jimlambie commented Jan 16, 2018

Hi @MichaelMarkieta,

Thanks for the issue report. I have seen this myself recently, and believe it is due to a default setting in the configuration that tells API where to find your custom collections/endpoints.

Can you please try adding this to your configuration file:

  "paths": {
    "collections": "workspace/collections",
    "endpoints": "workspace/endpoints",
    "hooks": "workspace/hooks"
  }

This assumes you have the following directories under "workspace":

  • collections
  • endpoints
  • hooks

Just remove any from the "paths" setting if you don't have them.

@MichaelMarkieta

This comment has been minimized.

Copy link
Author

MichaelMarkieta commented Jan 17, 2018

So the CLI does not generate a hooks directory under workspace so I added the paths.collections and paths.endpoints entries to my config file. This seems to have fixed it.

GET /api/collections
{
    "collections": [
        {
            "version": "1.0",
            "database": "library",
            "name": "books",
            "slug": "books",
            "path": "/1.0/library/books"
        },
        {
            "version": "1.0",
            "database": "library",
            "name": "users",
            "slug": "users",
            "path": "/1.0/library/users"
        }
    ],
    "media": {
        "buckets": [
            "mediaStore"
        ],
        "defaultBucket": "mediaStore"
    }
}

GET /1.0/library/books
{
    "results": [],
    "metadata": {
        "limit": 40,
        "page": 1,
        "fields": {},
        "sort": {
            "name": 1
        },
        "offset": 0,
        "totalCount": 0,
        "totalPages": 0
    }
}

POST /1.0/library/books
{
    "authorId": "4edd40c86762e0fb12000003",
    "name": "The Old Man and the Sea"
}

{
    "results": [
        {
            "_apiVersion": "1.0",
            "_createdAt": 1516163527185,
            "_createdBy": "XcSRnXDTtutZaWfpqMXmN69rj93fkZ",
            "_history": [],
            "_id": "e63adb31-b8f3-43b9-bba9-10d49b84c5ae",
            "_version": 1,
            "authorId": "4edd40c86762e0fb12000003",
            "name": "The Old Man and the Sea"
        }
    ]
}

GET /1.0/library/books
{
    "results": [
        {
            "_apiVersion": "1.0",
            "_createdAt": 1516163527185,
            "_createdBy": "XcSRnXDTtutZaWfpqMXmN69rj93fkZ",
            "_history": [],
            "_id": "e63adb31-b8f3-43b9-bba9-10d49b84c5ae",
            "_version": 1,
            "authorId": "4edd40c86762e0fb12000003",
            "name": "The Old Man and the Sea"
        }
    ],
    "metadata": {
        "limit": 40,
        "page": 1,
        "fields": {},
        "sort": {
            "name": 1
        },
        "offset": 0,
        "totalCount": 1,
        "totalPages": 1
    }
}

I should note that the tutorial does not follow the default collections schema in the latest API repo...

@WendySanarwanto

This comment has been minimized.

Copy link

WendySanarwanto commented Jan 17, 2018

👍
I can replicate this issue and clear it after following the work around. @jimlambie Why did you removed paths config in dadi api new wizard ? Are there any particular reasons ? Do you think it is a bug in the dadi api new wizard ?

@eduardoboucas

This comment has been minimized.

Copy link
Member

eduardoboucas commented Apr 5, 2018

Hi @WendySanarwanto. Can you just confirm that the issue has been resolved once you added paths to your config? If so, this has been captured in #371 and will be fixed in 3.1.

Thanks!

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