Giter Site home page Giter Site logo

beriberikix / codapi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nalgeon/codapi

0.0 1.0 0.0 141 KB

Interactive code examples for documentation, education and fun

Home Page: https://codapi.org

License: Apache License 2.0

Go 98.77% Makefile 1.13% Dockerfile 0.10%

codapi's Introduction

Interactive code examples

for documentation, education and fun ๐ŸŽ‰

Codapi is a platform for embedding interactive code snippets directly into your product documentation, online course or blog post.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ def greet(name):              โ”‚
โ”‚   print(f"Hello, {name}!")    โ”‚
โ”‚                               โ”‚
โ”‚ greet("World")                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  Run โ–บ  Edit  โœ“ Done
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Hello, World!                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Codapi manages sandboxes (isolated execution environments) and provides an API to execute code in these sandboxes. It also provides a JavaScript widget codapi-js for easier integration.

Highlights:

  • Automatically converts static code examples into mini-playgrounds.
  • Lightweight and easy to integrate.
  • Sandboxes for any programming language, database, or software.
  • Open source. Uses the permissive Apache-2.0 license.

For an introduction to Codapi, see this post: Interactive code examples for fun and profit.

Installation

See Installing Codapi for details.

Usage (API)

Call /v1/exec to run the code in a sandbox:

POST https://api.codapi.org/v1/exec
content-type: application/json

{
    "sandbox": "python",
    "command": "run",
    "files": {
        "": "print('hello world')"
    }
}

sandbox is the name of the pre-configured sandbox, and command is the name of a command supported by that sandbox. See Adding a sandbox for details on how to add a new sandbox.

files is a map, where the key is a filename and the value is its contents. When executing a single file, it should either be named as the command expects, or be an empty string (as in the example above).

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": "python_run_9b7b1afd",
  "ok": true,
  "duration": 314,
  "stdout": "hello world\n",
  "stderr": ""
}
  • id is the unique execution identifier.
  • ok is true if the code executed without errors, or false otherwise.
  • duration is the execution time in milliseconds.
  • stdout is what the code printed to the standard output.
  • stderr is what the code printed to the standard error, or a compiler/os error (if any).

Usage (JavaScript)

See codapi-js to embed the JavaScript widget into a web page. The widget uses exactly the same API as described above.

Contributing

Contributions are welcome. For anything other than bugfixes, please first open an issue to discuss what you want to change.

Be sure to add or update tests as appropriate.

License

Copyright 2023 Anton Zhiyanov.

The software is available under the Apache-2.0 license.

Stay tuned

โ˜… Subscribe to stay on top of new features.

codapi's People

Contributors

nalgeon avatar iamdeuterium avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.