Constructing Searchable Resources

This example constructs a search form and searchable collection resource. Navigate to this resource from the home via the ‘tenants’ link relation. Then search back on the collection.

search tenant resource

Goal

  • Create searches/filters on collections
  • Create cachable search forms
  • Demonstrate one way to process a search form to redirect back on a filterable collection

Anatomy of search

Methodlink relassociated routenotes
GET/start at the root of the api which has tenants as a link rel
GETtenants/tenant/follow the tenants link to get the collection
GETsearch/tenant/form/searchfollow the search form to get fields to fill in (this creates a filter in the current implementation)
POSTsubmit/tenant/search/fill in the form and send back to submit URL. Response returns 201 Created with Location header
GET/tenant/?q=follow the Location header returns a filtered search (feed) collection. Note: this is the same route as tenants link rel

Note: by convention a form can be submitted semantically. The submit link rel is usually the first option but it could be back on the originating collection. In this case, because the tenant collection is logically parented on the root rather than on a user (which it probably should but this collection is a convenient collection).

Anatomy of code

Add tenants

Below, you see on overview of the code, then you see the implementation.

Return tenants collection (with search link)

Below, you see on overview of the code, then you see the implementation.

Search form

Below, you see on overview of the code, then you see the implementation.

Make the Search

The search here is a simple technique to redirect back to the collection that takes an optional filter.

Below, you see on overview of the code, then you see the implementation.

Unlock the next chapter
A search is
A GET
A POST
A POST and then at least one GET
A GET, POST, GET ... GET