3

we have a Julia language calculation engine we want to trigger on command from a HTML webpage.

How can I connect from this application to a Julia instance. Is it possible to connect to Julia via a REST service?

2
  • Hi and welcome to Stack Overflow, please take a time to go through the welcome tour to know your way around here (and also to earn your first badge), read how to create a Minimal, Complete, and Verifiable example and also check How to Ask Good Questions so you increase your chances to get feedback and useful answers. Commented Oct 2, 2020 at 21:21
  • 2
    while this question is not perfect the answer provided by Matt B is very useful for others. Maybe it would be better to edit it instead of closing it. Commented Oct 3, 2020 at 12:53

1 Answer 1

7

You just need to have Julia listening on a port for incoming requests and have it respond accordingly. You can use an HTTP package (like HTTP.jl) to easily set up a REST endpoint:

import HTTP
using Sockets
compute(req::HTTP.Request) = HTTP.Response(200, "hello world")
const SERVER = HTTP.Router()
HTTP.@register(SERVER, "GET", "/test", compute)
HTTP.serve(SERVER, ip"127.0.0.1", 12345)

Now accessing http://127.0.0.1:12345/test should show you a page with the string hello world on it.

There are many frameworks that build atop this basic paradigm.

Sign up to request clarification or add additional context in comments.

2 Comments

If you want to run this in Linux from an address like 163.67.87.54 you need to change ip"127.0.0.1" with ip"0.0.0.0". The call will be: 163.67.87.54:12345/test
Yes, 0.0.0.0 will expose the service to the internet, whereas 127.0.0.1 will be localhost-only. Cf. superuser.com/questions/949428/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.