Skip to content

Commit

Permalink
native: add http module
Browse files Browse the repository at this point in the history
  • Loading branch information
Syuparn committed Jun 10, 2023
1 parent 4987d72 commit be394a3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions di/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func TestEvalKernelImportError(t *testing.T) {
`import("notfound")`,
object.NewFileNotFoundErr("failed to read native module \"notfound\": open modules/notfound.pangaea: file does not exist"),
},
{
`import("dummy_native_wrong")`,
object.NewSyntaxErr("failed to parse"),
},
}

for _, tt := range tests {
Expand Down
1 change: 1 addition & 0 deletions native/modules/dummy_native_wrong.pangaea
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 +
24 changes: 24 additions & 0 deletions native/modules/http.pangaea
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
_internal := import("http/internal")

Response := {
new: _init('status, 'body, 'headers),
}

Client := {
get: m{|url, headers: {}, queries: {}|
_internal['request](method: 'GET, url: url, headers: headers, queries: queries).{self._toResponse(\)}
},
post: m{|url, headers: {}, body: ""|
_internal['request](method: 'POST, url: url, headers: headers, body: body).{self._toResponse(\)}
},
put: m{|url, headers: {}, body: ""|
_internal['request](method: 'PUT, url: url, headers: headers, body: body).{self._toResponse(\)}
},
delete: m{|url, headers: {}, queries: {}|
_internal['request](method: 'DELETE, url: url, headers: headers, queries: queries).{self._toResponse(\)}
},
patch: m{|url, headers: {}, body: ""|
_internal['request](method: 'PATCH, url: url, headers: headers, body: body).{self._toResponse(\)}
},
_toResponse: m{|r| Response.new(r.status, r.body, r.headers)},
}

0 comments on commit be394a3

Please sign in to comment.