Typescript Axios example CLI
This repository contains a WebAssembly Component written in Typescript, which:
- Uses 
axiosto perform a web request - Runs with a single entrypoint (
wasi:cli'sruninterface) - Works with 
wash call - Works with WebAssembly ecosystem tooling (e.g. using 
wasmtime runorjco run) 
This example also showcases using external dependencies, in this case
the widely used HTTP request library axios.
Dependencies
![WARN] When building this project, ensure you are using a stable NodeJS release.
Use of node version management tools (ex.
nvmor more newer NVM compatible tools likefnm) are recommended -- a.nvmrcfile is included for easy use.
Building this project relies on the following installed software:
| Name | Description | 
|---|---|
wash | Wasmcloud Shell controls your wasmcloud host instances and enables building components | 
npm | Node Package Manager (NPM) which manages packages for for the NodeJS ecosystem | 
node | [NodeJS runtime][nodejs] (see .nvmrc for version) | 
wkg | (optional) wasm-pkg-tools project that makes it easy to pull down WIT definitions | 
Quickstart
With wash
To simply build the project into a runnable WebAssembly module, you can use wash:
wash buildTo get into a rapid development loop, clone the repo and run wash dev:
wash devwash dev does many things for you:
- Starts the wasmCloud host that can run your WebAssembly component
 - Builds this project (including necessary 
npmscript targets) - Builds a declarative WADM manifest consisting of:
- Your locally built component
 - A [HTTP server provider][http-client-provider] which will peform outgoing requests on your component's behalf
 - Necessary links between providers and your component so your component can make requests
 
 - Deploys the built manifest (i.e all dependencies to run this application) locally
 - Watches your code for changes and re-deploys when necessary.
 
With jco
Since using jco doesn't have any built in mechanism to resolve dependencies, you can use wash build to retrieve
the WIT dependencies for this project:
wash build
If you'd like to use WebAssembly ecosystem tooling, you can use wkg:
wkg wit fetch[!NOTE] If you've used
wash buildon the project at least once,wit/depsis likely already populated.
Once this command runs, you should find files & folders in the wit/deps directory, similar to the following:
wit
├── component.wit
└── deps
    ├── wasi-cli-0.2.3
    │   └── package.wit
    ├── wasi-clocks-0.2.3
    │   └── package.wit
    ├── wasi-filesystem-0.2.3
    │   └── package.wit
    ├── wasi-io-0.2.3
    │   └── package.wit
    ├── wasi-random-0.2.3
    │   └── package.wit
    └── wasi-sockets-0.2.3
        └── package.wit
8 directories, 7 files
To build and run the entire example (w/ the component served by jco), run the following:
npm install
npm run all[!NOTE] By default the example code makes a request to
https://jsonplaceholder.typicode.com/todos/1
You should see output like the following:
{
  "userId": 1,
  "id": 1,
  "title": "delectus aut autem",
  "completed": false
}
Send a request to the running component
Once wash dev is serving your component, to invoke the component and perform the HTTP request:
wash call wasmcloud:examples/invoke.callAdding Capabilities
To learn how to extend this example with additional capabilities, see the Adding Capabilities section of the wasmCloud documentation.