{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • API Design /
avatar image
0
Question by Gopal Singhania · Jun 07 at 07:08 AM · 315 Views api designrestrest apis

Design a rest api with multiple date range

I have a GET rest api and I want to do multiple date range search and that will be passed as query param in the api.

Query param name: start_create_time, end_create_time, start_update_time, end_update_time.

So how should I develop or design the rest api. Below are the 3 different approaches:

1. GET /api/REST/2.0/users/?start_create_time=2019-06-03&end_create_time=2019-06-05 last_update_time=2019-06-06☆t_update_time=2019-06-07

2. GET /api/REST/2.0/users/?start_create_time>2019-06-03&end_create_time<2019-06-05 last_update_time>2019-06-06☆t_update_time<2019-06-07

3. GET /api/REST/2.0/users/?start_create_time={"lt": 2019-06-03, "gt": 2019-06-06} & last_update_time={"lt": 2019-06-06, "gt": 2019-06-07} // pass a json object

I m not sure point 2 and 3 are valid way of designing the api. Can someone please suggest how I can achieve this.

Comment
Add comment
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Close

1 Answer

  • Sort: 
avatar image
1
Best Answer

Answer by Dino-at-Google   · Jun 10 at 02:41 PM

You have enough data to pass, that it starts feeling unwieldy passing it all as individual query params. So you have begun considering expressing that data in a json-formatted query param.

Some people have resorted to passing json in query params. I personally don't like the idea because it seems like it goes too far. I think the curly braces there makes the whole thing difficult to read and understand. To me, JSON is helpful in a payload, but seems counter-productive in a query param. But It is a matter of taste.

The thing you are trying to design looks like a search request. A GET with a bunch of constraints. I see several reasonable options.

  1. make the search request a POST. This means you can pass a json as the payload of the search. The constraints on the search can expand with your json .
  2. allow the search constraints to be encoded as a single string, and pass that as a single query param. Google for its search interface of course accepts a string that can express specific desires, such as "q=site:example.com bananas allinurl:ripe" You could do something similar eg "q=create:2019-06-01|2019-06-03 update:2019-06-07|2019:06-08" or something like that. The "gt" and "lt" feel unnecessary to me.

If I were doing this i would want the API to accept multiple date formats; with dashes, with slashes, or just seconds-since-epoch.

Also, what about timezones? Is there any thought to include the timezone in the time string? Does it matter?

Comment
Add comment Show 3 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gopal Singhania · Jun 11 at 03:31 AM 0
Link

Thanks Dino for the reply, as off now I will accept one date format (2019-06-03T07:50:20.940Z) which is standard for all the apis that we are developing.

avatar image Gopal Singhania · Jun 11 at 04:21 AM 0
Link

In the above api if I want to add a new param as amount which check amount>0,

e.g. . GET /api/REST/2.0/payments/? amount>0 then what is the best way of doing it.

avatar image Dino-at-Google ♦♦ Gopal Singhania   · Jun 11 at 10:54 PM 0
Link

Here again, it sounds like you want a Search API.

Consider implementing a simple query language and passing it as a query param.

Follow this Question

Answers Answers and Comments

75 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Pragmatic REST Webcast: How do you translate methods to be more data-oriented? 1 Answer

apigee-access.getMode() in NodeJS always returns "standalone" 1 Answer

YAML Payload request to APIGEE 2 Answers

Need suggestions on HTTP Status Code for trying to create an existing resource 2 Answers

Design Suggestion: Invalidating Access token on password change 0 Answers

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2019 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Members
  • Badges