Hi All,
I’ve manually migrated my content into v4 and am now working through updating my queries with the new API structure.
v3 had a /count route that would return the total number of entries.
I can’t seem to find this in v4. I used this for a stat counter that was visible on the front end.
Can someone please confirm if that is correct, where the new location might be or what I’d need to adjust to re-add ?
You are right that this is not an enabled route by default (I think).
But you can create a custom route easily, by creating/modifying two files:
First, create a custom route file for in your api/content-type folder (assuming you have a content type named product and want the total count of them):
hey @nextrapi , I’m just working through this now and I’m getting and error.
I’ve added the controller, the route and enabled permissions but it seems the database isn’t quite the same?
error: select "t0".* from "public"."blends" as "t0" where ("t0"."id" = $1) limit $2 - invalid input syntax for type integer: "count"
I would suggest not having a separate endpoint that simply counts the number of results. In v4, you will receive additional metadata for paginated results that will include a total attribute.
If this isn’t suitable for whatever reason, you should create an endpoint that returns the data and the total count in a single response. Otherwise, you’re doubling up on queries to the database and creating double the workload on all resources between the user and the data source.
Hello there. I have followed your code. However, there is only one single count route. I want all the default routes and the count route. How should I modify the code?
@Harisankar_Sahoo why is it working for me like this
module.exports = {
routes: [
{
// Path defined with a URL parameter
method: “GET”,
path: “/articles/count/view”,
handler: “article.count”,
},
],
};
and not working when i give
module.exports = {
routes: [
{
// Path defined with a URL parameter
method: “GET”,
path: “/articles/count”,
handler: “article.count”,
},
],
};