- Development Mode
- File System
- Data Types and Attributes
- Instance and Class Methods
- Model Configuration
The HTTP server allows you to perform actions and display files using HTTP and HTTPS protocols. The API can be accessed through a browser, cURL command, etc. You can access actions using URLs of the form
<url>/api/<action_name>. For example, if you want to access the
getPost action on a local server that is listening on port 8080, you would have to make a call to the URL
The JSON below shows an example of a response from the server.
Stellar also can serve files to the client. Stellar does not cache files; in each request files are read from disk. The following code is an example of how to send a file to the client from within an action:
// specifies the file to send to the client
The root of web server
/can be used to serve files (
/files) or actions (
/api). Their behavior can be changed using the configuration setting
api.config.servers.web.rootEndpointType(the default is to serve files).
When a file is not found the result is a page with an HTTP 404 error.
Whenever possible the mime package will be used to add a
Content-Typeheader in the response.
Note: see the File System section for more information about sending files.
For web clients (HTTP and HTTPS), you can define an optional RESTful mapping to help route requests to actions. If the client doesn’t specify an action via a parameter, and the base route isn’t a named action, Stellar will attempt to determine the action using the
routes.json file located in the module’s root folder.
There are three ways clients can access actions via a web server:
No route, using GET parameters:
Through basic routing, where the name of the action is found in the path after
/api, for example:
api.config.servers.web.rootEndpointTypesetting has the value
'file'it means that actions must be accessed using the prefix
/api. For the server to respond to an
api.config.servers.web.rootEndpointTypemust be set to
api.config.servers.web.rootEndpointTypeis set to
'api', routes starting with
The JSON below shows an example of a route declaration:
Routes will match the newest version of
apiVersion. If you want to have a specific route match a specific version of an action, you can provide the
apiVersion parameter in your route definitions. The following example shows this feature:
This would create both
/api/actionName/new, mapping to
apiVersion 1 and 2 respectively.
In your action and middleware, if a route was matched, you can see the details of the match by inspecting
action.connection.matchedRoute which includes
To disabling access to actions using
/api and only allow access the actions via the server root, you must change the value of
Note: if you do this, the
api.config.servers.web.rootEndpointTypesetting must be set to
'api', otherwise there will be no way to make calls to actions.
The parameters can be specified using GET or POST. Parameters are loaded in this order: GET -> POST (normal) -> POST (multipart). This means that if you access URL
example.com/?key=getValue and you post a variable
key=postValue as well,
postValue will be the value used.
File uploads from forms will also appear in
connection.params, but will be represented as an object with more information. That is, if you uploaded a file called “image”, you would have
connection.params.image.name (original file name), and
connection.params.image.type available to you.
Note: you can post BODY JSON payloads to Stellar in the form of an object or array.
Stellar uses the formidable form parsing library. You can upload multiple files to an action and they will be available within
connection.params as a formidable response object containing references to the original file name, where the uploaded file was stored temporarily, etc.
Note: since we never called
stellar.connectthe request is made via HTTP. More information can be found in the WebSocket section.