Skip to content

Commit 7c03915

Browse files
[MATLAB] Add simple HTTP GET MATLAB Client example (#45)
Adds a simple MATLAB HTTP GET client example --------- Lead-authored-by: Kevin Gurney <[email protected]> Co-authored-by: Sarah Gilmore <[email protected]> Signed-off-by: Ian Cook <[email protected]>
1 parent 46d5547 commit 7c03915

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

http/get_simple/matlab/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!---
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# HTTP GET Arrow Data: Simple MATLAB Client Example
21+
22+
This directory contains a minimal example of an HTTP client implemented in MATLAB. The client:
23+
24+
1. Sends an HTTP GET request to a server.
25+
2. Receives an HTTP 200 response from the server, with the response body containing an Arrow IPC stream of record batches.
26+
3. Creates an Arrow table from the record batches
27+
28+
To run this example, first start one of the server examples in the parent directory, then:
29+
30+
Run the MATLAB `client` script in "batch mode":
31+
32+
```sh
33+
matlab -batch client
34+
```

http/get_simple/matlab/client.m

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
% Licensed to the Apache Software Foundation (ASF) under one
2+
% or more contributor license agreements. See the NOTICE file
3+
% distributed with this work for additional information
4+
% regarding copyright ownership. The ASF licenses this file
5+
% to you under the Apache License, Version 2.0 (the
6+
% "License"); you may not use this file except in compliance
7+
% with the License. You may obtain a copy of the License at
8+
%
9+
% http://www.apache.org/licenses/LICENSE-2.0
10+
%
11+
% Unless required by applicable law or agreed to in writing,
12+
% software distributed under the License is distributed on an
13+
% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
% KIND, either express or implied. See the License for the
15+
% specific language governing permissions and limitations
16+
% under the License.
17+
18+
% The address of the HTTP server that
19+
% returns Arrow IPC Stream responses.
20+
server = "http://localhost:8008";
21+
22+
% Diagnostic output.
23+
disp("Reading Arrow IPC Stream from " + server + "...");
24+
25+
% Start timing.
26+
tic;
27+
28+
% Make an HTTP GET request to the local server
29+
% to fetch an Arrow IPC Stream and read all the
30+
% data into memory as a byte (uint8) array.
31+
options = weboptions(ContentType="binary");
32+
bytes = webread(server, options);
33+
34+
% Construct an Arrow RecordBatchStreamReader from the in-memory bytes.
35+
reader = arrow.io.ipc.RecordBatchStreamReader.fromBytes(bytes);
36+
37+
% Read an Arrow table from the in-memory bytes.
38+
arrowTable = reader.readTable();
39+
40+
% Stop timing.
41+
time = toc;
42+
% Round elapsed time to two decimal places.
43+
time = round(time, 2);
44+
45+
% Number of bytes received.
46+
nbytes = length(bytes);
47+
48+
% Diagnostic output.
49+
disp("DONE ✔");
50+
disp("---------------");
51+
disp("Results")
52+
disp("---------------");
53+
disp("Time (s): " + sprintf("%.2f", time));
54+
disp("Num Bytes: " + string(nbytes));
55+
disp("Num Rows:" + string(arrowTable.NumRows));
56+
disp("Num Columns:" + string(arrowTable.NumColumns));

0 commit comments

Comments
 (0)