Skip to content

Commit b9ec73a

Browse files
committed
Update API
1 parent 5e343d4 commit b9ec73a

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

Main.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import qualified Data.ByteString as B
3131
import qualified Data.ByteString.Char8 as BC8
3232
import qualified Data.ByteString.Lazy.Char8 as BLC8
3333

34+
import qualified Data.Aeson as A
35+
import Data.Aeson ((.=))
36+
3437
import qualified Data.Map as M
3538

3639
import Control.Applicative
@@ -165,10 +168,9 @@ server port = do
165168
response <- lift $ compile preludeModules code
166169
case runResponse response of
167170
Left err -> do
168-
status status500
169-
Scotty.text . fromString $ err
171+
Scotty.json $ A.object [ "error" .= err ]
170172
Right comp ->
171-
Scotty.text . fromString $ js comp
173+
Scotty.json $ A.object [ "js" .= js comp ]
172174

173175
main :: IO ()
174176
main = do

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ Very basic browser-based interface to the PureScript compiler.
77

88
### Compile PureScript code
99

10-
- Method: `POST`
11-
- Endpoint: `/compile/text`
10+
**POST /compile/text**
11+
1212
- Request body: PureScript code
13-
- Response body: Compiled Javascript code or error string
14-
- Status code: 200 (success) or 500 (error)
13+
- Response body: Either `{ js: "..." }` or `{ error: "..." }`
14+
- Status code: 200 (success)
1515

16+
The response does not use error codes, to make it easier to use the API from another domain using CORS.

trypurescript.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ author: Phil Freeman
1313
data-dir: ""
1414

1515
executable trypurescript
16-
build-depends: blaze-markup >=0.5.1.5 && <0.6,
16+
build-depends: blaze-markup >=0.5.1.5 && <0.6, aeson -any,
1717
bytestring >=0.10.0.2 && <0.11, base ==4.*, scotty -any,
1818
purescript ==0.6.9.3, containers -any, mtl -any, blaze-html -any,
1919
optparse-applicative -any, http-types >= 0.8.5, file-embed >=0.0.6

0 commit comments

Comments
 (0)