-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: better organization, cleanup (#5)
* cleanup: start reorganizing * ci * fix: shadowed variable name * refactor: add more binary types, move memory code to its own file * docs: show example with non-string input * cleanup: hlint * cleanup: reorganize * fix: don't free errors * cleanup: reorganize * cleanup: bring back Memory.store functions, remove unused imports * docs: add missing doc comments * docs: add link * cleanup: add explicit return code * cleanup: add tryInput * cleanup: count vowels example * fix: http example
- Loading branch information
Showing
13 changed files
with
610 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
# Revision history for haskell-wasm | ||
# Revision history for extism-pdk | ||
|
||
## 0.1.0.0 -- YYYY-mm-dd | ||
## 0.2.0.0 | ||
|
||
* API redesign, add automatic Haskell encoding using `ToMemory` and `FromMemory` classes | ||
|
||
## 0.1.0.0 -- 2023-09-28 | ||
|
||
* First version. Released on an unsuspecting world. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
module HTTPGet where | ||
|
||
import Data.Int | ||
import Extism.PDK | ||
import Extism.PDK.HTTP | ||
import Extism.PDK.Memory | ||
|
||
getInput = do | ||
req <- tryInput | ||
case req of | ||
Right (JSONValue x) -> return x | ||
Left e -> do | ||
putStrLn e | ||
url <- inputString | ||
return $ newRequest url | ||
|
||
httpGet = do | ||
-- Get URL from the host | ||
url <- input | ||
-- Create a new 'Request' | ||
let req = newRequest url | ||
-- Get URL or JSON encoded request from host | ||
req <- getInput | ||
-- Send the request, get a 'Response' | ||
res <- sendRequest req Nothing | ||
res <- sendRequest req (Nothing :: Maybe String) | ||
-- Save response body to memory | ||
outputMemory (memory res) | ||
-- Return code | ||
return 0 | ||
|
||
foreign export ccall "http_get" httpGet :: IO () | ||
foreign export ccall "http_get" httpGet :: IO Int32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
module Hello where | ||
|
||
import Extism.PDK | ||
import Data.Maybe | ||
import Extism.PDK | ||
import Foreign.C.Types | ||
|
||
defaultGreeting = "Hello" | ||
|
||
greet g n = | ||
output $ g ++ ", " ++ n | ||
|
||
testing = do | ||
-- Get a name from the Extism runtime | ||
name <- input | ||
name <- inputString | ||
-- Get configured greeting | ||
greeting <- getConfig "greeting" | ||
-- Greet the user, if no greeting is configured then "Hello" is used | ||
greet (fromMaybe defaultGreeting greeting) name | ||
|
||
foreign export ccall "testing" testing :: IO () | ||
foreign export ccall "testing" testing :: IO () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.