Http.put

From MiniScript Wiki
Revision as of 03:21, 17 April 2021 by JoeStrout (talk | contribs) (removed spurious parentheses from example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In Mini Micro, the http.put function sends data to a URL using the PUT method and returns the contents of the URL using the HTTP PUT protocol. It supports text, images, sounds, and raw binary data.

Arguments

Parameter Name Meaning
url URL of the web page or resource to fetch
data Data to put can be a string or a map
headers optional map of HTTP headers

Usage Notes

The type of the value returned depends on the MIME type reported by the server, as follows:

MIME Type MiniScript Type
image Image object
audio Sound object
text, javascript, xml, or json string
any other type RawData object

Example

The following example, typed on the Mini Micro command line puts data to a URL, retrieves a response, and displays Hello World from the test site http://postman-echo.com.

Note: depending on how the server is setup to respond to put requests you may get different types of data. the below example the server responds with application/octet-stream or a list of unicode number values which we must convert back into a string.

import "json" // for json.parse
import "listUtil" // for List.apply extension
request = http.put("http://postman-echo.com/put", "Hello World")
request_data = json.parse(request)
buffer = request_data.data.data
buffer.apply @char
buffer.join ""