apiURL = 'https://catfact.ninja/fact';
uri = matlab.net.URI(apiURL);
asAtDate = '2023-10-01T00:00:00';
airportCountryNames = ["Israel", "Ukraine"];
countryNamesJoined = strjoin(airportCountryNames, ',');
matlab.net.QueryParameter('as_at_date', asAtDate), ...
matlab.net.QueryParameter('airport_country_name', countryNamesJoined)];
disp(urlString);
https://catfact.ninja/fact?as_at_date=2023-10-01T00:00:00&airport_country_name=Israel,Ukraine
request = matlab.net.http.RequestMessage;
request.Method = matlab.net.http.RequestMethod.GET;
contentTypeField = matlab.net.http.field.ContentTypeField('application/json');
request.Header = [request.Header; contentTypeField];
uriObj = matlab.net.URI(uri);
response = send(request, uriObj);
disp(response.StatusLine);
StatusLine with properties:
ProtocolVersion: "HTTP/1.1"
StatusCode: OK
ReasonPhrase: "OK"
disp(response.Body.Data);
fact: 'The normal body temperature of a cat is between 100.5 ° and 102.5 °F. A cat is sick if its temperature goes below 100 ° or above 103 °F.'
length: 136
Please ensure that this matches the API specification you're working with. If the server expects a JSON payload in the body of the POST request, you would need to construct a JSON body rather than using query parameters. Adjust the contentTypeField and the request body as necessary based on the server's requirements.
Note:
- I used GET request for demo URL 'apiURL = 'https://catfact.ninja/fact'; % Change it as per your requirements'
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems
- Electrical and Electronics Engineering