YOUSEFUL / FILEMAKER
YsflHttp — function reference
Function prefix YsflHt_, 25 functions. HTTP and HTTPS through WinHTTP (system TLS,
system proxy settings, automatic gzip/deflate). Failures at the transport level return ? message
with the Win32/WinHTTP code in YsflHt_LastError; HTTP status codes are not failures: the body is
returned and YsflHt_Status tells you what happened.
Options
Space-separated key=value tokens or one per line. header=, part=, useragent=,
contenttype= and accept= take the rest of their line.
| option | meaning |
|---|---|
timeout=<sec> |
whole-request timeout (default 30); the request is aborted when it expires |
user=, password= |
credentials; sent preemptively as Basic unless auth= says otherwise |
auth=basic|digest|ntlm|negotiate |
authentication scheme (challenge-response schemes retry once) |
bearer=<token> |
Authorization: Bearer <token> |
header=Name: value |
extra header, repeatable |
contenttype=, accept=, useragent= |
common headers |
json / form |
shorthand content types |
file=<path> |
send the file's bytes as the body |
tofile=<path> |
save the body to a file and return 0 |
redirects=0 |
do not follow redirects |
verify=0 |
ignore certificate errors |
proxy=host:port |
explicit proxy |
decompress=0 |
keep compressed bodies |
charset=<name> |
force response decoding (utf-8, latin1, windows-1252, utf-16) |
field=, filename=, part=key=value |
Upload: form field name, file name, extra form fields |
Credentials embedded in the URL (https://user:pass@host/) are used as Basic auth. Cookies set by
servers are sent back automatically for the rest of the FileMaker session.
Functions
| Function | Returns |
|---|---|
YsflHt_Request ( method ; url ; {body} ; {options} ) |
response body text |
YsflHt_Get ( url ; {options} ), YsflHt_Delete, YsflHt_Head |
body text (Head returns "") |
YsflHt_Post ( url ; body ; {options} ), YsflHt_Put, YsflHt_Patch |
body text |
YsflHt_PostJSON ( url ; json ; {options} ) |
body; sends application/json, accepts JSON |
YsflHt_PostForm ( url ; fields ; {options} ) |
body; key=value lines url-encoded |
YsflHt_Upload ( url ; fileOrContainer ; {options} ) |
body; multipart/form-data with the file (path or container) plus part= fields |
YsflHt_Download ( url ; path ; {options} ) |
0; body saved to path |
YsflHt_GetContainer ( url ; {options} ) |
container named from Content-Disposition, filename=, or the URL |
YsflHt_GraphQL ( url ; query ; {variables} ; {options} ) |
JSON response; POSTs {"query":…,"variables":…} (variables must be a JSON object text) |
YsflHt_Status, YsflHt_StatusText |
last response status |
YsflHt_Headers |
last response headers, one per line |
YsflHt_Header ( name ) |
one header value (case-insensitive) |
YsflHt_ParseURL ( url ; part ) |
scheme, host, port, path, query, fragment, user, password |
YsflHt_URLEncode ( text ; {form} ), YsflHt_URLDecode ( text ) |
percent-encoding (form=1 uses + for spaces) |
YsflHt_SetDefaults ( {options} ) |
options applied before every call's own; "" resets |
YsflHt_Version, YsflHt_Register, YsflHt_LastError, YsflHt_LastErrorText |
Examples
# REST with a bearer token
Set Variable [ $json ; YsflHt_Get ( "https://api.example.com/v1/items?limit=10" ; "bearer=" & $token ) ]
If [ YsflHt_Status ≠ 200 ] # inspect $json for the error payload
# JSON POST
Set Variable [ $r ; YsflHt_PostJSON ( "https://api.example.com/v1/items" ; JSONSetElement ( "{}" ; "name" ; "Widget" ; JSONString ) ; "bearer=" & $token ) ]
# GraphQL
Set Variable [ $r ; YsflHt_GraphQL ( "https://api.example.com/graphql" ; "query($id: ID!) { user(id: $id) { name } }" ; "{\"id\":\"42\"}" ) ]
# file into a container, with a 2-minute timeout
Set Field [ Docs::File ; YsflHt_GetContainer ( "https://example.com/report.pdf" ; "timeout=120" ) ]
# upload a container as a form file
Set Variable [ $r ; YsflHt_Upload ( "https://example.com/upload" ; Docs::File ; "field=document part=folder=invoices" ) ]