1

I'm currently working on ng-admin.

I'm having a problem retrieving user data from my REST API (connected to a MongoDB) and displaying it.

I have identified the problem as the following:

When I enter http://localhost:3000/users into my browser, I get a list of all users in my database.

When I enter http://localhost:3000/users?_page=1&_perPage=30&_sortDir=DESC&_sortField=id, I get [] as a result.

I am quite new to this, I used both my browser and the POSTMAN Chrome extension to test this and get the same result.

Django
  • 343
  • 1
  • 4
  • 23

2 Answers2

0
http://localhost:3000/users_end=30&_order=DESC&_sort=id&_start=0

This (/users_end) is a different request than /users.

It should be:

http://localhost:3000/users?end=30&_order=DESC&_sort=id&_start=0

Or, by looking at the other parameters:

http://localhost:3000/users?_end=30&_order=DESC&_sort=id&_start=0

with end or _end being the first parameter (mark the ?).


Update (it is ? and before the _, I have edited.):

If adding parameters to the request returns an empty list, try adding only one at a time to narrow down the problem (there's probably an error in the usage of those parameters - are you sure you need those underscores?).

Danny_ds
  • 11,201
  • 1
  • 24
  • 46
0

Your REST API must have a way to handle pagination, sorting, and filtering. But ng-admin cannot determine exactly how, because REST is a style and not a standard. So ng-admin makes assumptions about how your API does that by default, that's why it adds these _end and _sort query parameters.

In order to transform these parameters into those that your API understands, you'll have to add an interceptor. This is all thoroughly explained in the ng-admin documentation: http://ng-admin-book.marmelab.com/doc/API-mapping.html

François Zaninotto
  • 7,068
  • 2
  • 35
  • 56