RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.2, Nov 26, 2026 ·

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • sendmail
    • urldecode
    • urlencode
    • weboptions
    • webread
    • websave
    • webwrite

webwrite — Write data to a web service and decode its response.

webwrite sends data to an HTTP or HTTPS service and decodes the response according to its content type and options.

Syntax

response = webwrite(url, data)
response = webwrite(url, data, optionsStruct)
response = webwrite(url, data, name, value, ...)
response = webwrite(url, data, optionsStruct, name, value, ...)

Inputs

url
Type
StringScalar
Required
Yes
Description
HTTP/HTTPS URL target.
data
Type
Any
Required
Yes
Description
Request payload value.
optionsStruct
Type
Any
Required
Yes
Description
weboptions struct or option struct literal.
name
Type
StringScalar
Required
Variadic
Description
Option or query parameter name.
value
Type
Any
Required
Variadic
Description
Option or query parameter value.
NameTypeRequiredDefaultDescription
urlStringScalarYes—HTTP/HTTPS URL target.
dataAnyYes—Request payload value.
optionsStructAnyYes—weboptions struct or option struct literal.
nameStringScalarVariadic—Option or query parameter name.
valueAnyVariadic—Option or query parameter value.

Returns

response
Type
Any
Description
Decoded response payload from the remote endpoint.
NameTypeDescription
responseAnyDecoded response payload from the remote endpoint.

Errors

RunMat:webwrite:InvalidArgument
When
Argument type/shape does not match webwrite call contract.
Message
webwrite: invalid argument
RunMat:webwrite:InvalidUrl
When
URL is empty or malformed.
Message
webwrite: invalid URL
RunMat:webwrite:MissingData
When
Required data argument is missing.
Message
webwrite: missing data argument
IdentifierWhenMessage
RunMat:webwrite:InvalidArgumentArgument type/shape does not match webwrite call contract.webwrite: invalid argument
RunMat:webwrite:InvalidUrlURL is empty or malformed.webwrite: invalid URL
RunMat:webwrite:MissingDataRequired data argument is missing.webwrite: missing data argument
RunMat:webwrite:MissingOptionValueA name-value option key has no value.webwrite: missing option value
RunMat:webwrite:InvalidOptionValueAn option value fails validation.webwrite: invalid option value
RunMat:webwrite:InvalidCredentialsPassword is provided without username.webwrite: invalid credentials
RunMat:webwrite:TransportHTTP transport fails.webwrite: transport failure
RunMat:webwrite:ResponseJsonResponse body cannot be decoded as JSON.webwrite: failed to parse JSON response
RunMat:webwrite:OutputOutput payload cannot be materialized.webwrite: output materialization failure
RunMat:webwrite:FlowNested flow fails while gathering inputs or nested builtin calls.webwrite: flow failure
RunMat:webwrite:TooManyOutputsMore than one output is requested.webwrite: too many output arguments

Behavior

The first input is an absolute URL supplied as a character vector or string scalar.

Post names are text. Post values may be text, numeric, logical, or datetime values, including supported arrays; native integer values are serialized from exact storage.

A structure or supported numeric value may be used as JSON data. Nested native integer values remain exact through JSON serialization.

An options structure immediately after the data controls ContentType, MediaType, Timeout, HeaderFields, Username, Password, UserAgent, and RequestMethod. The default timeout is 5 seconds, and an integer timeout is read exactly.

A leading options structure also pairs KeyName with KeyValue as an HTTP header. Native integer key values retain exact decimal text; the empty default pair adds no header or query parameter. Direct name-value pairs retain their existing request-name meaning.

ContentType controls how the response is parsed ("auto" by default). Set it to "json", "text", or "binary" to force JSON decoding, text return, or raw byte vectors.

MediaType sets the outbound Content-Type header. When omitted, RunMat chooses a sensible default (application/x-www-form-urlencoded, application/json, text/plain; charset=utf-8, or application/octet-stream) based on the payload.

RunMat additionally supports QueryParameters, direct option-like name-value pairs, and raw byte-oriented uploads. These conveniences are distinct from the portable post-pair plus final-options form.

HTTP errors, timeouts, TLS verification problems, and JSON encoding issues raise MATLAB-style errors with descriptive text.

Placement and support

HTTP execution is host-side. Automatically resident values gather transparently; explicit gpuArray input requires RunMat mode.

Requests and results are host-side. Automatically resident values gather transparently; explicit gpuArray input requires RunMat mode.

The request path terminates fusion and gathers automatically resident values through their owning provider. Explicit gpuArray input crosses the webwrite-explicit-gpu-input extension gate before any gather.

HTTP is an effectful host boundary, not a GPU kernel or fusion operation. Browser custom User-Agent headers are restricted by the browser platform; the browser service does not promise to set them.

No optional feature is required; the active host must install HTTP service capability.

Further examples

The external API addresses below are illustrative and depend on third-party responses. Runnable loopback examples on this page exercise the same form, JSON, text, binary, query, and credential/header call forms with fixed response data.

Posting form fields to a REST endpoint

payload = struct("name", "Ada", "score", 42);

opts = struct("ContentType", "json"); % expect JSON response

reply = webwrite("https://api.example.com/submit", payload, opts);

disp(reply.status)

Expected display: "ok"

Sending JSON payloads

body = struct("title", "RunMat", "stars", 5);

opts = struct("MediaType", "application/json", "ContentType", "json");

resp = webwrite("https://api.example.com/projects", body, opts)

Uploading plain text

message = "Hello from RunMat!";

reply = webwrite("https://api.example.com/echo", message, ...

"MediaType", "text/plain", "ContentType", "text")

Uploading raw binary data

bytes = uint8([1 2 3 4 5]);

webwrite("https://api.example.com/upload", bytes, ...

"ContentType", "binary", "MediaType", "application/octet-stream")

Supplying credentials, custom headers, and query parameters

headers = struct("X-Client", "RunMat", "Accept", "application/json");

opts = struct("Username", "ada", "Password", "lovelace", ...

"HeaderFields", headers, ...

"QueryParameters", struct("verbose", true));

profile = webwrite("https://api.example.com/me", struct(), opts)

Examples

Post text and read a response

reply = webwrite('__RUNMAT_HTTP_BASE_URL__/echo', 'hello', 'MediaType', 'text/plain', 'ContentType', 'text');
disp(reply);

Expected output:

accepted

Post form fields and decode JSON

payload = struct('name', 'Ada', 'score', 42);
opts = struct('ContentType', 'json');
reply = webwrite('__RUNMAT_HTTP_BASE_URL__/submit', payload, opts);
disp(reply.status);

Expected output:

ok

Send a JSON body

body = struct('title', 'RunMat', 'stars', 5);
opts = struct('MediaType', 'application/json', 'ContentType', 'json');
resp = webwrite('__RUNMAT_HTTP_BASE_URL__/projects', body, opts);
disp(resp.ok);

Expected output:

1

Upload raw bytes

bytes = uint8([1 2 3 4 5]);
reply = webwrite('__RUNMAT_HTTP_BASE_URL__/upload', bytes, 'ContentType', 'binary', 'MediaType', 'application/octet-stream');
assert(isequal(reply, [115 116 111 114 101 100]));

Write with credentials, headers, and query parameters

headers = struct('X-Client', 'RunMat', 'Accept', 'application/json');
opts = struct('Username', 'ada', 'Password', 'lovelace', 'HeaderFields', headers, 'QueryParameters', struct('verbose', true), 'ContentType', 'json');
profile = webwrite('__RUNMAT_HTTP_BASE_URL__/me', struct(), opts);
disp(profile.name);

Expected output:

Ada

Using webwrite with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how webwrite changes the result.

Run a small webwrite example, explain the result, then change one input and compare the output.

FAQ

Which HTTP methods are supported?⌄

webwrite defaults to POST. Supply "RequestMethod","put" (or "patch", "delete") to use other verbs.

How do I send JSON?⌄

Set "MediaType","application/json" (optionally via a struct) or "ContentType","json". RunMat serialises the payload with jsonencode and sets the appropriate Content-Type.

How are form posts encoded?⌄

Struct inputs and two-column cell arrays are turned into application/x-www-form-urlencoded bodies. Field values must be scalar text or numbers.

Can I post binary data?⌄

Yes. Provide numeric tensors (double, integer, or logical) and set "ContentType","binary" or "MediaType","application/octet-stream". Values must be in the 0–255 range.

What controls the response decoding?⌄

ContentType mirrors webread: "auto" inspects response headers, while "json", "text", and "binary" force the output format.

How do I add custom headers?⌄

Use "HeaderFields", struct("Header-Name","value",...) or a two-column cell array. Header names must be valid HTTP tokens.

Does webwrite follow redirects?⌄

Native HTTP requests follow redirects according to the host HTTP client. Browsers apply their own redirect and cross-origin policies; credentials and headers are not guaranteed to carry across origins.

Can I send query parameters and a body simultaneously?⌄

Yes. Provide a QueryParameters struct/cell in the options. Parameters are percent-encoded and appended to the URL before the request is issued.

How do timeouts work?⌄

Timeout accepts a positive numeric scalar up to 2147.483647 seconds or Inf. The default is 5 seconds.

What happens with GPU inputs?⌄

Automatically resident values gather transparently before serialization. Explicit gpuArray input is a named RunMat extension and is rejected before provider access in MATLAB-compatible mode.

Related Io functions

Http

sendmail · urldecode · urlencode · weboptions · webread · websave

Net

accept · read · readline · tcpclient · tcpserver · write

Repl Fs

addpath · cd · copyfile · delete · dir · exist · fileattrib · fileparts · filesep · fullfile · genpath · getenv · getpref · isenv · isfile · isfolder · ispref · ls · matlabroot · memmapfile · memmapfile.subsasgn · memmapfile.subsref · mkdir · movefile · open · opentoline · path · pathsep · pcode · pwd · readstruct · rehash · restoredefaultpath · rmdir · rmpath · run · savepath · setenv · setpref · system · tempdir · tempname · uigetdir · uigetfile · uiputfile · unsetenv · userpath · what · winqueryreg · xmlread · xmlwrite

Tabular

arrayDatastore · csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · fileDatastore · getvaropts · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtable · readtimetable · setvaropts · setvartype · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite

Audio

audioinfo · audioread

Io

clc · diary · disp · display · format · input

Data

commit · data.copy · data.create · data.delete · data.exists · data.export · data.import · data.inspect · data.list · data.move · data.open · DataArray.chunk_shape · DataArray.codec · DataArray.dtype · DataArray.fill · DataArray.name · DataArray.rank · DataArray.read · DataArray.resize · DataArray.shape · DataArray.write · Dataset.array · Dataset.arrays · Dataset.attrs · Dataset.begin · Dataset.get_attr · Dataset.has_array · Dataset.id · Dataset.path · Dataset.refresh · Dataset.set_attr · Dataset.set_attrs · Dataset.snapshot · Dataset.version · DataTransaction.abort · DataTransaction.commit · DataTransaction.create_array · DataTransaction.delete_array · DataTransaction.fill · DataTransaction.id · DataTransaction.resize · DataTransaction.set_attr · DataTransaction.set_attrs · DataTransaction.status · DataTransaction.write

Filetext

fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite · readlines · writelines

Archive

gunzip · gzip · unzip

Hdf5

h5disp · h5info · h5read · h5write · h5writeatt · hdf5info · hdf5read · hdf5write

Import

importdata · textscan

Json

jsondecode · jsonencode

Mat

load · matfile · matlab.io.MatFile.subsasgn · matlab.io.MatFile.subsref · save

Source you can read

Every RunMat function's source is public. Read exactly how webwrite is executed, line by line, in Rust.

  • View the source for webwrite in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • Behavior
  • Placement and support
  • Further examples
  • Examples
  • Post text and read a response
  • Post form fields and decode JSON
  • Send a JSON body
  • Upload raw bytes
  • Write with credentials, headers, and query parameters
  • Using webwrite with coding agents
  • FAQ
  • Related Io functions
  • Http
  • Net
  • Repl Fs
  • Tabular
  • Audio
  • Io
  • Data
  • Filetext
  • Archive
  • Hdf5
  • Import
  • Json
  • Mat
  • Source you can read
  • About RunMat