Code Monkey home page Code Monkey logo

httphandler's Introduction

HTTP

HTTP Handler for TCP Server designed for Wolfram Kernel (Mathematica, Engine)

Installation

Via Wolfram Paclet system

PacletInstall["KirillBelov/HTTP"]

Examples

Clone this repository

git clone https://github.com/KirillBelovTest/HTTP
cd HTTP

There is a set of usefull example, that helps to understand the logic of a webserver and its applications

APIFunction

This basically replicates the functionalify of Wolfram APIFunction available in Cloud only. However, using our approach one can run it locally

wolframscript -f Examples/APIFunction.wls

then open your browser at

http://127.0.0.1:8000/cellular?rule=69&step=500
http://127.0.0.1:8000/bars?v=1,2,3,4,5,6

what it does, it provides the URL parameters to the defined API function and generates the result for the reply

StaticWebsite

This is a simple example of templating using StringTemplate to embed the data into an html document from the request parameters or call an arbitary Wolfram Language function

wolframscript -f Examples/StaticWebsite.wls

It also shows how to work with media files and paths for the server. Those two WL logos are requested from two different folders, specified in Base parameters as an array of paths. Also the current date and a list with request parameters shows how to embed the WL function into the document.

FormExample

A bit more advanced example - a follow up to APIFunction - that unleash to power of modern HTML/CSS stack and POST method. It relies on Wolfram Script Pages framework for easier templating bringing simillar experiense if you was writting in PHP

wolframscript -f Examples/FormExample.wls

One can design anything in any share, using its favourite JS/CSS framework. Here Bootstrap is used. It has almost no limitations, when it comes to the static content generation compared to Wolfram Cloud

Each time you drag a slider and click to Submit button, it sends POST request, recalculates a new plot and sends to a user. No JS required, just old good HTTP and reqular forms processing.

POST

This is a demonstartion of how to work with POST request. It can process only text files and text data unfortonately. When you upload the data and submit it, it redirects to the specified page, while the recived data is printed to the console

wolframscript -f Examples/POST.wls

WSP

This demo shows on how to work with WSP (Wolfram Script Pages) template engine and generate content based on user's request passed via URL parameters

wolframscript -f Examples/WSP.wls

index.wsp

<?wsp With[{color = $CurrentRequest["Query", "color"]}, ?>
    <div style="width:100px; height:100px; background-color: <?wsp color ?>"></div>
<?wsp ] ?>

As one can see, it puts a color variable into the style of a div element. Then if one open a page at

http://127.0.0.1:8000/?color=cyan

it will show

Plotter ⚗️

This features a file explorer & graph viewer made out of independent components simillar to what people do in a modern WEB

wolframscript -f Examples/Plotter.wls

One can navigate through the folders

and open the sample data

For each file there is a view.wsp component that generates SVG image and embeds it into a page.

Cool, ha? Thinking about what you can do, makes Wolfram Cloud to be just a toy for the rich kids - @JerryI

Plotter2 🔭

One could go even further utulizing the power of WebSockets and WLJS (a tiny Wolfram Language Interpreter running in a browser). So that we do not need to spend resources on generating ugly static SVGs, but providing just the raw data and make browser and Javascript to do the actual plotting

wolframscript -f Examples/Plotter2.wls

The naviagtion is the same, but when a user opens a file it shows a placeholde, while Javascript is pumping the data from the server via WebSockets (aka hydrate the HTML element) and then plots the received data

This is not about rocket science, but a combination of a few simple open-source tools, that moves Wolram Language beyong the notebook interface

httphandler's People

Contributors

jerryi avatar kirillbelovtest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jerryi

httphandler's Issues

HTTPServer doesn

Nothing works.
wolframscript -f Examples/APIFunction.wls Staring HTTP server... Open your browser on http://127.0.0.1:8000cellular?rule=69&step=500 Open your browser on http://127.0.0.1:8000bars?v=1,2,3,4,5,6
Opening browser on the link doesn't work - not found

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.