Message Boards Message Boards

[LiVE] Building Wolfram Cloud APIs to JS Frontends and Serverless Backends

Live Coding Sessions

The four sessions work up to a mini-project in the last 40 minutes of session 4.

The links for session 4 are now included below. There are session links for TwitchTV and YouTube. In session 3 I examine how to rasterize arbitrary WL expressions that are neither Images nor Graphics. We also go over how to control ImageSize and AspectRatio to accommodate HTML requirements (or vis-a-versa).

Along with Andreas Lauschke and Alan Calvitti I've undertaken the following 'live coding' sessions along the line of APIs where WL is the computational end point. I will not walk-through the JavaScript environment setup (unless there is enough demand). All the needed bit’s and pieces are readily available with very good documentation.

TwitchTV: - Session 1 - Session 2 - Session 3 - Session 4 YouTube: - Session 1 - Session 2 - Session 3 - Session 4

I frequently say front-end and back-end environments overlook (or under appreciate) the computation-side. However, with a few development requirements the quant-side can deliver to the front-end folks exactly what they need and reduce the amount of processing logic in the front-end. It also conforms to the development team and code writing philosophy of separation of concerns and duties. This opens the door to more modular teams and code with easy to understand handshakes between components and teams.

All the Notebooks, JavaScript code, YouTube and TwitchTV links are in my GitHub repository.

We start with the most simple use of APIFunction[…] I can think of then step into use cases that confront simple issues, which if not understood upfront, can cause delays and frustration for one of more team members. We make API calls to external resources from inside APIFunction[…] and get and put data from and to Wolfram Cloud. We look at producing and returning exactly the structure of JSON needed by the JavaScript (front-end).

This is followed with a look at using APIFunction[…] with NodeJS (backend) building up to dealing with the dreaded CORS issues and look into some security issues.

Lastly, we will look at a few use cases for integrating to AWS resources.

I will update this post and my GitHub as we proceed.

9 Replies

This is an excellent and thorough exploration of Wolfram Language-as-backend design, which is a very powerful paradigm for when a FormFunction frontend doesn't quite cut it. I particularly enjoyed the discussion in session 3 of image sizing and formatting, which is a tricky problem I've dealt with several times and still haven't quite gotten the hang of!

Also, regarding IntegerName, I tried it with a Real and (despite its name) it seems to work:

In[1]:= IntegerName[-0.01]

Out[1]= "minus zero point zero one"
POSTED BY: Jesse Friedman
Posted 5 years ago

Very cool! Thanks for piloting this I just watched the first session, it's extremely beneficial: the WebExecute framework is one of the latest areas of WL that I've started exploring, and I can't believe I went this long without using it.

I also didn't realize I could extract parts of Message objects: passing error messages of failed API calls back to front-end code is a very good use case of why you'd want to have such flexible structures.

Love the tips of trade bit about lack of analogous structures between languages, like the Real value parameters, and adjusting them to fit the JS code.

Just a lot of great stuff in here, and I'm only one session in!

POSTED BY: Jesse Dohmann

Hi there, I'm Riccardo from WRI. I really like the work you have been doing, those live coding sessions are really nice.

We have been developing a new technology that is allowing you to serve web content from your local machine, we recently published it on GitHub.

https://github.com/WolframResearch/WolframWebEngineForPython

The server is based on some very mature technology and is intended for production, I think it's a perfect fit for the type of applications you are doing (JS frontend with WL backend).

This server is also very useful for developing, because you can develop your APIFunction locally, which allows you to do Print / Echo in order to debug your code and see the output directly in the terminal that is running your server.

Once your APIFunction is coded correctly you can decide how to deploy to production: you can deploy on the Wolfram cloud or use a Wolfram Engine to serve content with your own hardware.

Since I'm the main author of this repo, I would really appreciate a feedback on this technology, so if you have time let us know what you think about it.

Cheers!

Thank you for your comments and the slap on the back of the head ;-) Perhaps it a version thing. I swear I tried it and I sure am happy you showed me because I don’t know when I would have come back to this.

I happy you're enjoying and finding it useful. I can't wait to here what you have to say after the 4 vedio ;-)

Good timing. I'll have a look at the URL and give you some feedback.
I recently notice https://reference.wolfram.com/language/WolframNotebookEmbedder/ and have been testing it. Just today I noticed the community post Wolfram Notebook Embedder https://community.wolfram.com/groups/-/m/t/1788578 released by Jan Poeschko. You can see my comments down the post - to summarize - I use ReactJS and NodeJS extensivly and I've always wanted a way for a React component (at arbitragy levels in the component tree) to be responcible for the creation and mangement of WL containers (full of WL goodies) so that React can be used to control and App state and render requriements such that when a WL container living in a React component is part of the render - well - let the magic happen.

Hey, I just found these videos and they are great! I have a project where i want to use Wolfram as the backend to a microservice and this series covers the subject in more detail than i ever hoped to find. In addition to the subject coverage, I really appreciated watching the debugging and the practical discussions around how you go about building these services, handling errors, reals and such.

I have a question: The APIFunction calls take a simple flat association. I want to send a nested JSON structure that may include lists of objects and could run up to several K bytes. Is there a way to put the input data in the body of the message instead of the URL?

POSTED BY: Michael Johnston

Hi there, this might help you:

https://reference.wolfram.com/language/ref/AllowedCloudParameterExtensions.html

This is the easiest way to do it, it's not using Body as JSON however. But if you are fine in sending the payload as POST encoded data and add the payload in one of the parameters, you can do that.

Let me know if that helps.

Riccardo

I am fine fine with the POST method, but I wasn't successful. Can you offer a suggestion?

Thanks Michael

POSTED BY: Michael Johnston
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract