Results 1 to 9 of 9
  1. #1
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default Regarding Idempotent Request and non Idempotent Request

    Hi to all ,can you please tell me what is the difference between idempotent non idempotent Requests.

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    As far as I know, an idempotent request can be executed multiple times without altering any system data, state, or resource. Conversely, a non-idempotent request will make some change some data or resource when executed. GET is usually idempotent, whereas POST is usually not.

  3. #3
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    thanks for u r quick reply and sorry for my late response ,I am some what busy with my work.
    Java Code:
    As far as I know, an idempotent request can be executed multiple times without altering any system data, state, or resource
    Can u please elaborate what u said about with small example.
    Last edited by sandeepsai39; 09-07-2010 at 06:05 AM.

  4. #4
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Well I don't think a whole HTTP example is necessary here, but you could consider this an idempotence example:
    Java Code:
    class IdempotenceExample {
        bool meaningless;
        int x;
        public IdempotenceExample() {
            this.meaningless = true;
            this.x = 5;
        }
        public int IdempotentMethod() {
            return this.x;
        }
        public int NonIdempotentMethod() {
            this.meaningless = false;
            return this.x;
        }
        public void TestIdempotence() {
            int a = IdempotentMethod();
            int b = IdempotentMethod();
            int c = IdempotentMethod();
            int d = IdempotentMethod();
            int e = NonIdempotentMethod();
            int f = NonIdempotentMethod();
        }
    }
    You will notice that IdempotentMethod does not change the value of x (or anything else for that matter), instead it just fetches the value, no matter how many times you do it. NonItempotentMethod, however, changes the value of meaningless on its first execution, which means that it is not idempotent.

  5. #5
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    thank u ,I got it . That means GET request only get the value of 'x' from IdempotentMethod() method in your example .So it doesn't change the value of either boolean value or int value,but a POST req can change the values of int or boolean variables with method NonIdempotentMethod().

    Thank u for spending your valuable time.

  6. #6
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Yes, often a POST request will make queries to a database or other data, or notify the server of some activity. A GET request will not. ;)

    You're very welcome!

  7. #7
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    By the way I forgot one thing ,How to plan our code in such way that for POST req also it should behave in an idempotent manner[means it shouldn't effect any data].Is it possible?

  8. #8
    georgemc is offline Senior Member
    Join Date
    Sep 2008
    Posts
    135
    Rep Power
    0

    Default

    The HTTP POST method need not be idempotent. That's not part of its contract. GET, PUT, DELETE etc, yes, but POST isn't intended to be idempotent. I think you might have the impression that idempotency equals read-only. It doesn't. Idempotency means that if you invoke the same function more than once with the same exact data, the state of the system is not further affected. Clearly, the first time said function is invoked with that data, a change is allowed. For example, a method that sets a boolean value is idempotent, since every time you call it with 'false', the result is the same. A method that flips a boolean value, isn't idempotent, because the result is different every time you invoke it.

  9. #9
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

Similar Threads

  1. urgent request
    By mudit222 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 04-23-2010, 10:12 AM
  2. MDB/JMS Request/Response
    By rkands in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 03-04-2010, 03:38 PM
  3. JSF Request value on Page2
    By mwildam in forum JavaServer Faces (JSF)
    Replies: 5
    Last Post: 09-17-2009, 10:12 AM
  4. First post as per request
    By happyknappy in forum Introductions
    Replies: 3
    Last Post: 07-30-2008, 02:33 AM
  5. request.get not using generics
    By Nicholas Jordan in forum Java Servlet
    Replies: 4
    Last Post: 07-27-2008, 03:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •