Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4050162
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:02:09+00:00 2026-05-20T14:02:09+00:00

Given that we provide a restful api that serves book entities listening at /books

  • 0

Given that we provide a restful api that serves book entities listening at

/books

And a client can get a book at the usual

GET /books/{id}

Suppose that we want to begin offering discounts on books to only our most vigilant buyers. These buyers would be given a discount code, and that code will reduce the price of the book.

Thus, a generic response may be

 GET /books/4
 {"id":4, "price":"24.95"}

Where a response to a query with a discount code may be

 GET /books/4
 {"id":4, "price":"24.95", "yourPrice":"19.95"}

The back-end processing we can get figured out, but what is the best practice for a client submitting a discount code over a restful api?

Certain books will be eligible for discounts while others will not. Discounts will not be broad (20% off everything), but instead will map to a specific price for that particular code (or client/code combo).

We’ve considered:

  • kludging the url

    GET /codes/{someCode}/books/{id}

  • Adding the code in a header value

  • Using a query string

    GET /books?code=myCode

  • anything else?

EDIT: Our goal is not to implement single-use codes. Instead, these discount codes could be used some fixed number of times for some fixed set of books.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:02:09+00:00Added an answer on May 20, 2026 at 2:02 pm

    I like using query variables. I just looked at the RESTful Web Services book, my main reference in this area, and they say:

    Use query variables only to suggest
    arguments being plugged into an
    algorithm… If two URIs differ only
    in their query variables, it implies
    they’re the different sets of inputs
    into the same underlying algorithm.

    It seems to me your discount codes are inputs to a discounting algorithm.

    Charles

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that Twitter doesn't provide users' email addresses to apps [1], how can a
My objective is create an apache module that will provide RESTful services (i.e., we
I know there are some web sites that provide this service but given that
Given that Monarch/Groundwork is made to provide a GUI interface to Nagios, this should
I have an Activity that will query a RESTful API every x seconds (polls
Given that the web application doesn't have su privileges, I'd like to execute a
Given that an input String may be specified as follows: read(xpath(‘...’)) or xpath(‘...’) or
Given that I have a Foo model w/ the standard Rails timestamp columns what
Given that sorl isn't an app directory wide and the template tag definition lives
Given that the Rails Way seems to be not to use foreign key constraints,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.