REST easy with kbmMW #15 – Handling HTTP POST

Intro

Ive been asked questions about how to handle POST via kbmMW’s smart service based REST.

This blog post explains the typical POST variations, and how to handle them in kbmMW.

POST variants

A web/REST client can POST data in multiple ways:

  1. As value data in the path part of the URL
    eg. POST http://localhost/myservice/myfunction/10/20
  2. As key/value data in the query part of the URL
    eg. POST http://localhost/myservice/myfunction?arg1=10&arg2=20
  3. As FORM key/value data in the body.
    eg. POST http://localhost/myservice/myfunction
    and then body contains:
    name1=value1&name2=value2
  4. As XML or JSON data in the body.
    eg. POST http://localhost/myservice/myfunction
    and then body contains:
    {“name1″:”value1″,”name2″:”value2”}
  5. As Multipart body typically as part of a file upload.

You extract data in different ways depending on the way the client has chosen to send them.

  1. You use:
  2. You use:
  3. You use:

    and in MyFunction’s implementation:
  4. There are multiple ways:
    1.  If the data is “known” you can define a class to receive the data. Eg.

      An instance of AData will then be provided to the function MyFunction and automatically freed upon exit of MyFunction.
    2. If the data is “unknown” you can use a XML or JSON streamer. Eg.
  5. It is somewhat more complex to handle, but kbmMW contains a TkbmMWHTTPMultiParts class that can be used to decipher multipart data containing multipart boundaries.This time we first need to figure out if its actually a multipart body. Then we need to figure out whats the boundary identification between each part, and then we can start to split it up and handle each part separately.

Prologue

There are many more features in the kbmMW REST smart service. Some of them are explained in other blog posts in this “REST easy” serie, You may also want to check out the documentation section containing more than 600 pages of documentation by visiting our site at http://www.components4developers.com, and look for the kbmMW documentations section.

If you like this, please share the word about kbmMW wherever you can and feel free to link, like, share and copy the posts of this blog to where you find they could be useful.

Oh… and whats about that featured image? It’s the mail boxes in Denmark… In danish we call that “Post kasser”. Due to the internet, fewer and fewer of these are to be found around the landscape. The last 10 years around 85% of all post offices has disappeared. Instead local grocery shops handle snail mail with various success.

Author: kimbomadsen

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.