0.0.10 • Published 8 months ago

njp-piston v0.0.10

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

NJP Piston Library

Interact with the Piston API using this lightweight JavaScript/TypeScript wrapper.

Installation

Using npm:

npm install njp-piston

Usage

To use the Piston library, follow the below steps:

  1. Import the piston method:
import { piston } from 'njp-piston';
  1. Create an instance of Piston pointing to your Piston server:
const pistonInstance = await piston("http://localhost:2000");
  1. Use the available methods on the instance:

Fetching Configuration

console.log(pistonInstance.configuration);

Getting Runtimes

const runtimes = await pistonInstance.getRuntimes();
console.log(runtimes);

Execute Source Code

In this example, we're executing a Python code that reads an input and prints a greeting:

const result = await pistonInstance.executeSourceCode(
    "r = input()\nprint('Hello ' + r)", 
    "python", 
    "World!"
);
console.log(result);

Example

Here's a complete example putting it all together:

import { piston } from 'njp-piston';

(async () => {
    const pistonInstance = await piston("http://localhost:2000");

    console.log(pistonInstance.configuration);
    console.log(await pistonInstance.getRuntimes());
    console.log(await pistonInstance.executeSourceCode("r = input()\nprint('Hello ' + r)", "python", "World!"));
})();

API Reference

Further API documentation can be found at the piston website https://piston.readthedocs.io/en/latest/api-v2/.

License

This library is released under the MIT License.

0.0.10

8 months ago

0.0.8

8 months ago

0.0.6

8 months ago

0.0.5

8 months ago

0.0.3

8 months ago

0.0.1

8 months ago