# Examples

# HTML Form

request form-post-example {
  method = "POST"
  url = "http://httpbin.org/post"

  headers = {
    "content-Type" = "application/x-www-form-urlencoded"
  }

  body = {
    key = "value"
    another-key = "another value"
    another-key-2 = "another value-2"
    another-key-3 = "another value-3"
    number-value = 99.99
  }
}
$ restbeast r form-post-example
HTTP/1.1 200 OK

{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "another-key": "another value", 
    "another-key-2": "another value-2", 
    "another-key-3": "another value-3", 
    "key": "value", 
    "number-value": "99.99"
  }, 
  "headers": {
    "Accept-Encoding": "gzip", 
    "Content-Length": "114", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Cookie": "", 
    "Host": "httpbin.org", 
    "User-Agent": "RestBeast/0.13.0", 
    "X-Amzn-Trace-Id": "Root=1-60230f69-3defdc753b001a0b456f7cf6"
  }, 
  "json": null, 
  "origin": "213.127.105.230", 
  "url": "http://httpbin.org/post"
}

# File upload

Uploading any file is done by using readfile function.

request post-file {
  method = "POST"
  url = "http://httpbin.org/post"

  body = readfile("./example-image-file.png")
}
$ restbeast r post-file
HTTP/1.1 200 OK

{
  "args": {}, 
  "data": "data:application/octet-stream;base64,iVBORw0KGgoAAAANSUhEUgAAA.......GyUAAAAASUVORK5CYII=", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept-Encoding": "gzip", 
    "Content-Length": "18686", 
    "Content-Type": "image/png", 
    "Cookie": "", 
    "Host": "httpbin.org", 
    "User-Agent": "RestBeast/0.13.0", 
    "X-Amzn-Trace-Id": "Root=1-60230dce-0f0513f06971510e17d2a607"
  }, 
  "json": null, 
  "origin": "213.127.115.230", 
  "url": "http://httpbin.org/post"
}

# Multipart upload

Providing a boundary is optional, it's safe to just use multipart/form-data. Uploading any file is done by using readfile function.

request multipart-example {
  method = "POST"
  url = "http://httpbin.org/post"

  headers = {
    "content-Type" = "multipart/form-data; boundary=custom-boundary"
  }

  body = {
    key = "value"
    another-key = "another value"
    another-key-2 = "another value-2"
    another-key-3 = "another value-3"
    number-value = 99.99
    image-file = readfile("./example-image-file.png")
  }
}
$ restbeast r post-example-form
HTTP/1.1 200 OK

{
  "args": {}, 
  "data": "", 
  "files": {
    "image-file": "data:application/octet-stream;base64,iVBORw0KGgoAAAANSUhEUgAAAccAAAIxCAYAAA......./sIjH9F0CGyUAAAAASUVORK5CYII="
  }, 
  "form": {
    "another-key": "another value", 
    "another-key-2": "another value-2", 
    "another-key-3": "another value-3", 
    "key": "value", 
    "number-value": "99.99"
  }, 
  "headers": {
    "Accept-Encoding": "gzip", 
    "Content-Length": "19858", 
    "Content-Type": "multipart/form-data; boundary=custom-boundary", 
    "Cookie": "", 
    "Host": "httpbin.org", 
    "User-Agent": "RestBeast/0.13.0", 
    "X-Amzn-Trace-Id": "Root=1-60230ca2-4306bd633a2ae42e753f0bf8"
  }, 
  "json": null, 
  "origin": "213.127.115.230", 
  "url": "http://httpbin.org/post"
}
Last Updated: 12/7/2021, 10:26:52 PM