You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* The Try PureScript client no longer uses a bundle of preloaded
modules; fix a sentence which says it does
* Document that the request body must be a module called Main
* Document the formats of the various JSON responses in more detail
* Document the fact that we now expose the output directory from
compile.purescript.org
The server is a very basic web service which wraps the PureScript compiler, allowing clients to send PureScript code to be compiled and receiving either compiled JS or error messages in response.
77
+
It is hosted at <https://compile.purescript.org/>.
77
78
78
79
### Compile PureScript code
79
80
80
-
**POST /compile**
81
+
#### POST /compile
81
82
82
-
- Request body: PureScript code
83
-
- Response body: Either `{ js: "..." }` or `{ error: "..." }`
83
+
- Request body: PureScript code defining a module whose name must be Main
84
84
- Status code: 200 (success)
85
85
86
-
Note that if the code in the request body fails to compile, this is considered a success from the perspective of the API, so compilation failures will be returned with 2xx status codes.
86
+
Response body on compilation success:
87
+
88
+
```javascript
89
+
{
90
+
"js":"...", // a string containing JavaScript code
91
+
"warnings": [ ... ] // an array of warnings, using the same format as the
92
+
// compiler's --json-errors flag
93
+
}
94
+
```
95
+
96
+
Response body on compilation failure:
97
+
98
+
```javascript
99
+
{
100
+
"error": {
101
+
"tag":"CompilerErrors",
102
+
"contents": [ ... ] // an array of errors, using the same format as the
103
+
// compiler's --json-errors flag
104
+
}
105
+
}
106
+
```
107
+
108
+
Response body on other errors (eg, the name of the module in request body was not Main, or the request body was too large)
109
+
110
+
```javascript
111
+
{
112
+
"error": {
113
+
"tag":"OtherError",
114
+
"contents":"..."// a string containing an error message
115
+
}
116
+
}
117
+
```
118
+
119
+
Note that the API returns a 200 response in all of the above cases; in particular, if the code in the request body fails to compile and the API returns errors, this is still considered a success.
87
120
Among other things, this makes it easier to use the API from another domain using CORS.
88
121
89
-
The output code will contain references to preloaded modules using `require` calls.
122
+
The output code will contain references to any imported modules using `require` calls.
90
123
To run these files in the browser, it is necessary to either use a `require` shim (such as require1k), or replace these calls and deploy a bundle of precompiled modules.
91
-
The Try PureScript client uses the second approach.
124
+
The Try PureScript client uses the first approach.
125
+
126
+
#### GET /output/:module/(index.js|foreign.js)
127
+
128
+
The server exposes the compiled JS for all of the modules it has access to.
129
+
If the compiled JavaScript code in the response includes a `require` call such as `require(../Web.HTML/index.js)`, then the client is expected to arrange things so that this `require` call provides access to the JavaScript code available at the URL path `/output/Web.HTML/index.js`, via a shim or otherwise.
92
130
93
131
### Configuration
94
132
@@ -99,4 +137,4 @@ The server application takes the following arguments on the command line:
0 commit comments