-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGettingStarted.m
More file actions
81 lines (81 loc) · 3.25 KB
/
Copy pathGettingStarted.m
File metadata and controls
81 lines (81 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
%[text] # Getting Started with matlab-http-server
%[text] This Live Script gives a quick orientation to the toolbox and points to the main usage patterns.
%[text] - define API routes by subclassing `mhs.ApiController`
%[text] - start the server in base MATLAB
%[text] - optionally serve frontend files from the same server \
%%
%[text] ## Installation
%[text] Install the toolbox from a release `.mltbx`, or clone the repository and add the `toolbox` folder to your MATLAB path.
%[text] ```matlab
%[text] git clone https://github.com/PVDecker1/matlab-http-server.git
%[text] addpath(fullfile(pwd,'matlab-http-server','toolbox'))
%[text] ```
%[text] The minimum supported MATLAB release is R2022b.
%%
%[text] ## First Server
%[text] Create a `MatlabHttpServer`, register one or more controllers, and call `start()`.
%[text] ```matlab
%[text] server = MatlabHttpServer(8080);
%[text] server.register(MyController());
%[text] server.start();
%[text] ```
%[text] Controller classes inherit from `mhs.ApiController` and implement `registerRoutes`.
%[text] ```matlab
%[text] classdef MyController < mhs.ApiController
%[text] methods (Access = protected)
%[text] function registerRoutes(obj)
%[text] obj.get('/api/hello', @obj.getHello);
%[text] end
%[text] end
%[text] methods
%[text] function res = getHello(~, ~, res)
%[text] res.json(struct('message', 'Hello from MATLAB'));
%[text] end
%[text] end
%[text] end
%[text] ```
%%
%[text] ## Static File Serving
%[text] Static file serving is a first-class feature of the toolbox.
%[text] ```matlab
%[text] server = MatlabHttpServer(8080);
%[text] server.register(MyController());
%[text] server.serveStatic("public/");
%[text] server.start();
%[text] ```
%[text] This same-origin pattern is a convenient way to host a browser UI and an API from one MATLAB process.
%%
%[text] ## Transport Options
%[text] The default transport uses Java sockets coordinated by a MATLAB timer loop and works in base MATLAB.
%[text] The Go sidecar is optional and can be selected explicitly:
%[text] ```matlab
%[text] server = MatlabHttpServer(8080, Transport="go");
%[text] ```
%[text] The core server does not require Instrument Control Toolbox or Parallel Computing Toolbox.
%%
%[text] ## Examples
%[text] The toolbox includes runnable examples in `toolbox/examples`.
%[text] - `BasicExample` for simple routing
%[text] - `MultiControllerExample` for larger APIs
%[text] - `StaticSiteExample` for frontend hosting
%[text] - `SignalAnalyzer` for a same-origin React-style UI \
%%
%[text] ## Testing and Release Quality
%[text] Run the automated test suite before packaging or releasing the toolbox.
%[text] ```matlab
%[text] buildtool test
%[text] buildtool ci
%[text] ```
%[text] The repository also includes markdown guides for routing, request and response handling, deployment, and static file serving in `toolbox/doc`.
%%
%[text] ## Next Steps
%[text] Continue with these references:
%[text] - `getting-started.md` for the markdown quickstart
%[text] - `routing.md` for path parameters and route ordering
%[text] - `request-response.md` for request and response behavior
%[text] - `static-file-serving.md` for frontend hosting patterns \
%[appendix]{"version":"1.0"}
%---
%[metadata:view]
% data: {"layout":"inline"}
%---