Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
URL for total count of items in a resource
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alexander Zaslonov  
View profile  
 More options Oct 6 2012, 12:13 pm
From: Alexander Zaslonov <zaslonov.alexan...@gmail.com>
Date: Sat, 6 Oct 2012 09:13:05 -0700 (PDT)
Local: Sat, Oct 6 2012 12:13 pm
Subject: URL for total count of items in a resource

Dear all,

Recently I designed an interface for API and run into dilemma of how to
define URL for total count of items in a resource. Having done some
research I found a couple approaches for that:

1. Define a URL like /service/resource/count.

2. Return the total count in the header, so that it's possible to get it
using HEAD method without loading the resource itself.

Could you please comment on these approaches or propose any other?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bill Walton  
View profile  
 More options Oct 6 2012, 2:51 pm
From: Bill Walton <bwalton...@gmail.com>
Date: Sat, 6 Oct 2012 13:51:10 -0500
Local: Sat, Oct 6 2012 2:51 pm
Subject: Re: [api-craft] URL for total count of items in a resource

Hi Alexander,

On Sat, Oct 6, 2012 at 11:13 AM, Alexander Zaslonov <

I'm currently in the midst of a similar project.  I'm developing in Rails
and neither of those options was an obvious fit.  What I ended up doing is
defining a couple of query parameters to signal the need for counts and
sums:  computed and computation_type.  computed can be true or false.
computation_type can be count or sum.  So to retrieve a count of active
clients, for example, the URL is:
/clients?computed=true&computation_type=count&client_status=active.  I'm
not altogether happy with it, but it makes it easy on the controller and
easy to understand inasmuch as the same query without the two parameters
retrieves the actual data elements.

HTH,
Bill


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kristof Kotai  
View profile  
 More options Oct 7 2012, 8:16 am
From: Kristof Kotai <kotai.kris...@gmail.com>
Date: Sun, 7 Oct 2012 05:16:30 -0700 (PDT)
Local: Sun, Oct 7 2012 8:16 am
Subject: Re: URL for total count of items in a resource

When using HEAD, you should be returning exactly the same response as if
GET was used, except for the response body.

That means if you go with this approach, you should be including the
"count" in the headerlist also when GET is used.

GET   /books
HEAD  /books

Not sure how much overhead does that add to the execution time on the
server, if not much, then use that. Otherwise, create a separate URI like
the one in 1.

GET   /books/count

(I would rather use something more general though, so later you could add
something else here too
GET   /books/meta)

Cheers


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexander Zaslonov  
View profile  
 More options Oct 15 2012, 1:51 pm
From: Alexander Zaslonov <zaslonov.alexan...@gmail.com>
Date: Mon, 15 Oct 2012 10:51:37 -0700 (PDT)
Local: Mon, Oct 15 2012 1:51 pm
Subject: Re: URL for total count of items in a resource

Thank you guys, it seems there are still no common practices for that.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dean Landolt  
View profile  
 More options Oct 15 2012, 7:14 pm
From: Dean Landolt <d...@deanlandolt.com>
Date: Mon, 15 Oct 2012 19:13:35 -0400
Local: Mon, Oct 15 2012 7:13 pm
Subject: Re: [api-craft] Re: URL for total count of items in a resource

On Mon, Oct 15, 2012 at 1:51 PM, Alexander Zaslonov <

zaslonov.alexan...@gmail.com> wrote:
> Thank you guys, it seems there are still no common practices for that.

Check out the Range header -- it's the best kept secret of http. It's not
just for bytes -- you can define your own range type. For instance dojo
defines an "items" range for paginating in its JsonRestStore. The semantics
of the range header gives you a consistent way to treat resources as
collections and as an added bonus it gives you a nice clean way to slice or
paginate any of your collections. But it also gives you a good way to
optionally provide a total count with any request:

GET /books
Accept-Ranges: items

200 OK
Content-Range: items 0-10/10

And of course this works fine for HEAD requests.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »