Socket
Socket
Sign inDemoInstall

@deislabs/wasi-experimental-http

Package Overview
Dependencies
2
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @deislabs/wasi-experimental-http

Experimental HTTP library for AssemblyScript


Version published
Weekly downloads
14
Maintainers
4
Created
Weekly downloads
 

Readme

Source

@deislabs/wasi-experimental-http

npm version

Experimental HTTP client library for AssemblyScript.

Using this library

First, install the package to your project:

$ npm install @deislabs/wasi-experimental-http --save

Then, import the package and create a request using the RequestBuilder:

// @ts-ignore
import { Console } from "as-wasi";
import {
  Method,
  RequestBuilder,
  Response,
} from "@deislabs/wasi-experimental-http";

export function post(): void {
  let body = String.UTF8.encode("testing the body");
  let res = new RequestBuilder("https://postman-echo.com/post")
    .header("Content-Type", "text/plain")
    .method(Method.POST)
    .body(body)
    .send();

  print(res);
}

function print(res: Response): void {
  Console.log(res.status.toString());
  Console.log(res.getHeader("Content-Type"));
  let result = String.UTF8.decode(res.bodyReadAll().buffer);
  Console.log(result);
}

After building a WebAssembly module using the AssemblyScript compiler, the module can be executed in a Wasmtime runtime that has the experimental HTTP functionality enabled (the crate to configure it can be found in this repo):

{
    "content-length": "374",
    "connection": "keep-alive",
    "set-cookie": "sails.Path=/; HttpOnly",
    "vary": "Accept-Encoding",
    "content-type": "application/json; charset=utf-8",
    "date": "Fri, 26 Feb 2021 18:31:03 GMT",
    "etag": "W/\"176-Ky4OTmr3Xbcl3yNah8w2XIQapGU\"",
}
{"args":{},"data":"Testing with a request body. Does this actually work?","files":{},"form":{},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-60393e67-02d1c8033bcf4f1e74a4523e","content-length":"53","content-type":"text/plain","abc":"def","accept":"*/*"},"json":null,"url":"https://postman-echo.com/post"}
"200 OK"

FAQs

Last updated on 15 Jun 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc