mmhttp
Topics covered in this chapter:
- New functionality for the Mosel language
- Control parameters
- Constants
- Procedures and functions
- I/O drivers
The module mmhttp makes it possible to communicate with external components via HTTP requests. Both modes, client or server side, can be used in a Mosel model: the client routines allow a Mosel model to send the HTTP requests GET, POST, PUT, PATCH or DELETE to a web service. A model may also act as a web service by starting the integrated HTTP server. In this mode, the model gets notified about connections from remote clients via specific mmjobs events. The model can then reply to these requests using a set of dedicated routines.
To use this module, the following line must be included in the header of the Mosel model file:
uses 'mmhttp'
New functionality for the Mosel language
The type reqqueue
The type reqqueue can be used to implement multithreaded HTTP servers: it represents a queue of pending HTTP requests to be processed by the server. A queue of this type must be declared as a global shared entity such that each cloned submodel of the master model can access it. A submodel ready to handle a new request has to call httpreqpop in order to warn the queue manager of its availability and then wait for an event. When the server receives a request that has to be processed by one of these submodels it moves this request to the queue using httpreqpushlim or httpreqpush, as a result the request is sent to one of the available submodels that is notified as if the request had been directly received from the network (see Section HTTP server). If no submodel is ready, the request is recorded in the queue until a model becomes available for processing it.
Constants
mmhttp defines the following constants for frequently used HTTP status codes (the codes of the 200 series indicate success, the 400 series are error codes, according to the RFC 2616 specification). Note that the textual representations of HTTP status codes can be obtained via function httpreason.
- HTTP_OK: 200
- HTTP_CREATED: 201
- HTTP_ACCEPTED: 202
- HTTP_NO_CONTENT: 204
- HTTP_RESET_CONTENT: 205
- HTTP_BAD_REQUEST: 400
- HTTP_UNAUTHORIZED: 401
- HTTP_PAYMENT_REQUIRED: 402
- HTTP_FORBIDDEN: 403
- HTTP_NOT_FOUND: 404
- HTTP_METHOD_NOT_ALLOWED: 405
- HTTP_NOT_ACCEPTABLE: 406
- HTTP_PROXY_AUTHENTICATION_REQUIRED: 407
- HTTP_REQUEST_TIMEOUT: 408
I/O drivers
The mmhttp module publishes the url driver with which a URL can be used as a file. Thanks to this facility it is possible to use files stored on an HTTP enabled file server just as if they were located on the local file system. For example, the following command downloads and executes the Mosel file "hello.mos" stored on the web server mysrv:
> mosel exec mmhttp.url:http://mysrv/hello.mos
Driver url
url:URL
The file name for this driver is a URL. Currently only HTTP URLs are supported (i.e. the name must begin with "http://"). The behaviour of the driver depends on the file operation:
- reading
- A GET request is sent to the specified URL at the time of opening the file. The following read operations are executed directly from the result stream generated by the server.
- writing
- The written data is first saved into a temporary file and then sent to the specified URL via a PUT request when the file is closed.
- deleting
- When deleting a file ( e.g., using fdelete) through this driver a DELETE request is sent to the specified URL.
© 2001-2025 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.