How to get an auto-generated FeathersJS service to store and retrieve JSON data?

214 Views Asked by At

After auto-generating a FeatherJS App and Service, I have used an HTTP POST to send JSON data to the service in the POST body, and I have tried to use GET requests to retrieve this data.

When I POST and GET the only data I see is the ID of a record that seems to have been created, but the JSON data itself is nowhere to be seen.

My understanding was that the un-edited auto-generated Service should implement CRUD functionality and that data should be in the request body.

I would like to know if I have missed something, or what additional steps need to be taken to save and retrieve data with my FeathersJS service.

I have installed feathersjs/cli using

npm install @feathersjs/cli -g

Then I generated an App using:

feathers generate app

I specified that the App should use npm, should be a REST app and should use Mocha + assert for testing.

I have then generated a service using:

feather generate service

My service is called test and uses an NeDB database.

I then start the application with

npm start

I can access the expected Feathers home page with my web browser on http://localhost:3030/

I have tried using Postman to POST and GET Json, but it's not working.

Using Postman, I do a GET on the URL http://localhost:3030/test

The response I get is a 200 OK, with the body:

{
    "total": 0,
    "limit": 10,
    "skip": 0,
    "data": []
}

I then POST to the same URL with a body of:

{
    "number": 3
}

and I get a 201 Created response, which seems successful, and the body returned is:

{
    "_id": "M7Z35WlIwRBueCo7"
}

When I then do a GET request to the URL: http://localhost:3030/test/M7Z35WlIwRBueCo7

I get a response of 200 OK, with the body:

{
    "_id": "M7Z35WlIwRBueCo7"
}

I am always seeming to only get the ID of a record, and never the actual record itself.

I would have expected to see a returned body that looked more like this

{
    {
        "number": 3
    },
    "_id": "M7Z35WlIwRBueCo7"
}
0

There are 0 best solutions below