Dear Eliot,

I cannot speak for React directly, yet we have had excellent results when using 
vuejs or Vanilla JS + RestXQ.
For all projects involving any sort of HTML frontend, our approach is twofold:

We provide RestXQ Endpoints, usually authentication is handled via the session 
module, or in more advanced cases using JWT-Auth-Tokens or a combination of 
both.
For simple scenarios we then have our BaseX-Jetty-Server serve the static 
files, i.e. our HTML + JS Code directly from the filesystem, if it gets more 
complex we can outsource the web app to nginx for example.

I then map the default servlet to “/” — so files from ./webapp will be served 
at http://localhost:8984/
I then map the RESTXQ-servlet to “/api” — so calls to these endpoints will be 
served by RestXQ.

I set up a simple project here outlining this structure 
https://git.basex.io/ms/ml-example-webapp — everything is served from BaseX and 
the project is pretty self-contained.

I would not, however, serve the HTML and JS Contents via RestXQ endpoints — 
while technically possible you might probably use a lot of tooling support that 
works on plain HTML & JS(X) files and people not familiar with embedding HTML 
in XQuery Module or functions will likely lose their minds over the inexistence 
of named entities or escaping of curly braces 😊
Plus: should you ever decide to ditch RestXQ and use another API (not 
recommended) you could do that more easily.

Hope this is useful to you.

Best
Michael

Von: BaseX-Talk <[email protected]> im Auftrag von 
Eliot Kimber <[email protected]>
Datum: Freitag, 20. Mai 2022 um 00:18
An: [email protected] <[email protected]>
Betreff: [basex-talk] BaseX, RESTXQ, and React?
I’m starting to learn React in the context of enhancing a React-based site 
created by others (lightstep.com/incident-reponse/docs).

I’m also developing a non-trivial web application in BaseX (the Project Mirabel 
system I’ve mentioned before).

For Mirabel I just hacked some pages using RESTXQ and the least CSS and 
JavaScript I could get away with, cribbing liberally from the out-of-the-box 
BaseX web apps.

But as I learn about React and its companion, Material UI, I’m thinking that 
there’s probably a lot of power to combining React with RESTXQ as a way to 
build a top-notch site with lots of interactivity at relatively low cost (React 
and MUI provide all the interaction implementation details you might want). But 
I’m not sure what this would mean in practice.

I’m wondering if anyone else has done this or at least thought about it enough 
to have some ideas about what to do or not do?

In addition, at the most recent DITA conference, Convex 2022, George Bina 
presented a very interesting experiment in generating React components for DITA 
topics where the components did the dynamic content resolution at delivery time 
rather than at HTML building time, enabling practical incremental update of 
DITA-based content through a React-based site. The same technique could be 
applied to RESTXQ by generating XQuery modules for individual topics. But an 
advantage of a React approach is that it’s more general and could be used with 
any React-based site. But in any case it’s gotten me thinking more about the 
generation of information

I see React being used mostly in statically-generated sites that are published 
through something like Netlify but my Mirabel application is very much almost 
entirely dynamic in that most of the content is the result of queries.

One could treat BaseX as a supplier of microservices via a REST API and that’s 
probably how most users of BaseX with React do it, if for no other reason than 
separate groups are probably responsible for the web stuff and the BaseX stuff.

But in the case of my Mirabel application it’s a single team doing everything 
with limited web development knowledge but access to talented web designers. So 
having all the web stuff also in BaseX makes development and maintenance easier 
with the team we have. We’re not JavaScript programmers but we can manage 
composing React components together and doing the minimal programming needed to 
make them behave appropriately.

Clearly I can just have RESTXQ-generated pages import the React libraries and 
supporting components directly and I can generate JSX code as inline scripting 
and maybe that’s the best approach for an all-RESTXQ site but maybe there’s 
something better?

Or does stepping up to a proper React site that uses BaseX as a source of 
microservices make more sense, even for this small project?

Thanks,

Eliot
_____________________________________________
Eliot Kimber
Sr Staff Content Engineer
O: 512 554 9368
M: 512 554 9368
servicenow.com<https://www.servicenow.com>
LinkedIn<https://www.linkedin.com/company/servicenow> | 
Twitter<https://twitter.com/servicenow> | 
YouTube<https://www.youtube.com/user/servicenowinc> | 
Facebook<https://www.facebook.com/servicenow>

Reply via email to