POST

Submitting plain text data

POST
/resource
HTTP/1.1
Accept: */*
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Host: example.com
User-Agent: rest-man/1.1.0 (darwin21 arm64) ruby/3.1.2p20
Content-Type: text/plain
Content-Length: 14
Hello, world!
HTTP/1.1
200
OK
Content-Type: text/plain
Text received.
simple
advance
resource
cli
response = RestMan.post "http://example.com/resource", "Hello, world!", { content_type: "text/plain" }

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> text/plain
response.body                   #=> Text received.
response = RestMan::Request.execute(
  method: :post,
  url: "http://example.com/resource",
  payload: "Hello, world!",
  headers: { content_type: "text/plain" }
)

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> text/plain
response.body                   #=> Text received.
resource = RestMan::Resource.new("http://example.com/resource")
resposne = resource.post(
  "Hello, world!",
  {content_type: "text/plain"}
)

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> text/plain
response.body                   #=> Text received.
$ echo "Hello world!" | restman post http://example.com/resource

Text received.

Submitting form data

POST
/resource
HTTP/1.1
Accept: */*
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Host: example.com
User-Agent: rest-man/1.1.0 (darwin21 arm64) ruby/3.1.2p20
Content-Type: application/x-www-form-urlencoded
Content-Length: 27
first_name=john&last_name=hil
HTTP/1.1
200
OK
Content-Type: text/html
<html> <body> Thank you, John Hill, for submitting the form! </body> </html>
simple
advance
resource
cli
response = RestMan.post 'http://example.com/resource', { first_name: "John", last_name: "Hill" }

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> text/html
response.body                   #=> <html> ... 
response = RestMan::Request.execute(
  method: :post,
  url: 'http://example.com/resource',
  payload: { first_name: "John", last_name: "Hill" }
)

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> text/html
response.body                   #=> <html> ... 
resource = RestMan::Resource.new("http://example.com/resource")
response = resource.post({ first_name: "John", last_name: "Hill" })

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> text/html
response.body                   #=> <html> ... 
$ echo "first_name=john&last_name=hil" | restman post http://example.com/resource

<html>
<body>
Thank you, John Hill, for submitting the form!
</body>
</html>

Posting JSON data with custom headers

POST
/api/resource
HTTP/1.1
Accept: application/json
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Host: example.com
User-Agent: rest-man/1.1.0 (darwin21 arm64) ruby/3.1.2p20
Content-Type: application/json
Authorization: Bearer token123
Content-Length: 32
{"username"=>"johnhill", "age"=>20}
HTTP/1.1
200
OK
Content-Type: application/json
{ "status": "success", "message": "Data updated successfully" }
simple
advance
resource
cli
response = RestMan.post(
  'http://example.com/api/resource',
  {
    username: "johnhill",
    age: 30,
  }.to_json,
  {
    authorization: "Bearer token123",
    accept: :json,
    content_type: :json
  }
)

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> application/json
response.body                   #=> {"status": ...}
response = RestMan::Request.execute(
  method: :post,
  url: 'http://example.com/api/resource',
  payload: {
    username: "johnhill",
    age: 30,
  }.to_json,
  headers: {
    authorization: "Bearer token123",
    accept: :json,
    content_type: :json
  }
)

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> application/json
response.body                   #=> {"status": ...}
resource = RestMan::Resource.new("http://example.com/api/resource")
response = resource.post(
  {
    username: "johnhill",
    age: 30,
  }.to_json,
  {
    authorization: "Bearer token123",
    accept: :json,
    content_type: :json
  }
)

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> application/json
response.body                   #=> {"status": ...}
RestMan CLI hasn't support JSON submit currently.

Posting a file directly

POST
/api/image
HTTP/1.1
Accept: */*
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Host: example.com
User-Agent: rest-man/1.1.0 (darwin21 arm64) ruby/3.1.2p20
Content-Type: image/jpeg
Content-Length: 143685
["JPEG binary data goes here"]
HTTP/1.1
200
OK
Content-Type: text/plain
Image uploaded successfully
simple
advance
resource
cli
response = RestMan.post(
  'http://example.com/api/image',
  File.new("./files/profile.jpg", 'rb'),
  {content_type: :jpg}
)

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> text/plain
response.body                   #=> Image uploaded successfully
response = RestMan::Request.execute(
  method: :post,
  url: 'http://example.com/api/image',
  payload: File.new("./files/profile.jpg", 'rb'),
  headers: { content_type: :jpg }
)

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> text/plain
response.body                   #=> Image uploaded successfully
resource = RestMan::Resource.new("http://example.com/api/image")
response = resource.post(
  File.new("./files/profile.jpg", 'rb'),
  {content_type: :jpg}
)

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> text/plain
response.body                   #=> Image uploaded successfully
RestMan CLI hasn't support file upload with custom headers

Posting files with multipart

POST
/api/profile
HTTP/1.1
Accept: */*
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Host: example.com
User-Agent: rest-man/1.1.0 (darwin21 arm64) ruby/3.1.2p20
Content-Type: multipart/form-data; boundary=RubyFormBoundary123
Content-Length: 8362
------RubyFormBoundary123 Content-Disposition: form-data; name="username" johnhill ------RubyFormBoundary123 Content-Disposition: form-data; name="profile1"; filename="profile.jpg" Content-Type: image/jpeg [BINARY DATA FOR JPEG IMAGE] ------RubyFormBoundary123 Content-Disposition: form-data; name="profile2"; filename="profile2.jpg" Content-Type: image/jpeg [BINARY DATA FOR JPEG IMAGE] ------RubyFormBoundary123--
HTTP/1.1
200
OK
Content-Type: application/json
{ "status": "success", "message": "Profile updated successfully", "url": "/images/profile.jpg" }
simple
advance
resource
cli
response = RestMan.post(
  'http://example.com/api/profile',
  {
    username: 'johnhill',
    profile1: File.new("./files/profile.jpg", 'rb'),
    profile2: File.new("./files/profile2.jpg", 'rb')
  }
)

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> application/json
response.body                   #=> {"status": ...}
response = RestMan::Request.execute(
  method: post,
  url: "http://example.com/api/profile",
  payload: {
    username: 'johnhill',
    profile1: File.new("./files/profile.jpg", 'rb'),
    profile2: File.new("./files/profile2.jpg", 'rb')
  }
)

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> application/json
response.body                   #=> {"status": ...}
resource = RestMan::Resource.new("http://example.com/api/profile")
resposne = resource.post(
  {
    username: 'johnhill',
    profile1: File.new("./files/profile.jpg", 'rb'),
    profile2: File.new("./files/profile2.jpg", 'rb')
  }
)

response.code                 #=> 200
response.headers                #=> Hash
response.headers[:content_type] #=> application/json
response.body                   #=> {"status": ...}
RestMan CLI hasn't support multipart request currently.