I want to build a site that calls a pi and displays the results. The problem is the API is a jar file that i normally import into a java project and go from there. However i want to build a web app but not sure i how can interact with my jar file.
I see some folks executing the jar in a command line but im not sure that the same, i want to interact with all the methods exposed to me via this java API by the jar file.
any ideas if there is a popular way of doing this or a framework i could use?
You can use spring MVC, you can build web apps there, consume the API jar file and do whatever you want in the views(frontend) with javascript and so on.
I recommend you use thymeleaf, which is pretty simple and easy.
If you want to build a fast app I also recommend you to use spring boot
You will build an app within minutes
https://spring.io/guides/gs/spring-boot/
Related
I have thoroughly searched the web about creating a website using React as a front end and PHP as a backend for like a week now. I have found many solutions about configuring webpacks and stuffs. But most of them only aim for index.html. So, I decided to create one LARGE react app and used CDNs of React, ReactDOM, and Babel to run it on index.php which is running on XAMPP. The main reason for creating one large app is because I cannot use full functionality of creating components and importing them.
But now, I want to use MDBootstrap, and its React components. But I cannot use them since importing is not available. I have watched tutorials and read articles about webpack and configured it. But all those were for index.html. And lastly, I have also found tutorials using PHP, XAMP(MySQL), and React. However, most of them run on Node server rather than XAMP server.
So I want to create something like
Website
react_app
index.php
where react_app is created by create-react-app or does have a same functionality as it like imports and stuffs. I do know that NPM server runs index.html from /build/, but I do want to run it on XAMP server using index.php.
Here is a link you can follow to do what you are asking for https://medium.com/#MartinMouritzen/how-to-run-php-in-node-js-and-why-you-probably-shouldnt-do-that-fb12abe955b0
and a possible other answer here Execute PHP scripts within Node.js web server
Only thing is, it is not really advisable to do this. It carries a number of security risks. I would advice you learn to seperate concerns and follow the Model-View-Controller (MVC) design attached to React.
You can still have React as your view while PHP is in the back. requests are sent and received through an api call. Check out this simple tutorial on achieving this https://blog.bitsrc.io/how-to-build-a-contact-form-with-react-js-and-php-d5977c17fec0
I hope this helps you with what you need. If it doesn't, let me know. glad to help!
I understand that React is frontend, and NodeJS is the backend that allows Javascript code to function outside of a browser. What I don't understand (and this is after following tutorials online on setting up a React project and a NodeJS project) is why I have to create an instance of each.
For example, in my React project, I managed to create a website. But because I needed a backend, I decided to use NodeJS. But I'm doing NodeJS tutorials, and I can create a website using NodeJS too. I'm confused because right now, it's appearing to be that React and NodeJS do the SAME THING.
I have never worked with NodeJS before so I am a bit confused. I was under the impression that I would just use NodeJS to host the backend, but after seeing that I'm literally having to create an entire website with NodeJS, I don't understand how I'm supposed to use React and NodeJS together.
How do the two, React and NodeJS, integrate together to create a fully-functioning web app? I have yet to see something online that clearly breaks down how the two interact.
React is front-end library. It provides great tooling for creatiing user interfaces. And it creates a single page application. Which means when you open a react app. It does not reload and its really fast.
While you could also use nodejs and something like handlebars to create a website. But that website would be rendered on server and then served to the user. But its alot more than that. There are a lot of things that you want to do on the server. Like authentication. You want that part to be secure. So you keep it on the server.
Now the answer to the final part of your question.
For a fully functional app. You would use react to create user interfaces. And nodejs for creating an API which your react app will call.
NodeJS is not just regular javascript, it is a javascript runtime that sits on top of a C++ engine called V8, provided by Google. Node executes outside the browser, whereas React / Vue / Angular / etc are in-browser javascript frameworks.
React is a whole separate animal; it is a framework that renders its own DOM in the browser. It is a javascript engine that is configured to optimize DOM manipulation.
While the development pattern of frontend and backend appear similar, they are doing different things. React is handling component lifecycles, applying dynamic style rules, processing in-browser data, and making API calls. Node is handling requests from the browser, coordinating access to the server's file system, managing network I-O, performing cryptographic evaluation, etc. Because of these different responsibilities, Node makes use of different dependencies (read: node modules) than a frontend framework.
Ultimately, Node and React communicate through HTTP calls (or, less frequently, through a WebSocket or SOAP protocol).
It would behoove you to read about how node works under the hood.
NodeJS is just a runtime that allows you to run javascript code outside of the browser.
In order to compile and transpile the react JS app, they use webpack and other tools which runs over NodeJS.
NodeJS will serve as your backend, whereas ReactJS will create the interface/UI where you can actually manipulate your server (nodeJS). So first you'll write your NodeJS server or API. You don't need to use ReactJS to create a frontend that would interact with your node server, like you said you can use NodeJS to create your views as well through a different library. ReactJS is just one choice of many for the front end of your NodeJS app.
The point is that react and any other SPA library is working on a client-side (browser).
React fetch and consume the data from the server API.
You don't need to use Node.js for building API. You can use various frameworks based on the technology you prefer.
If you are not familiar with the Back End, you can use https://www.npmjs.com/package/http-server to have a fake API service and can build the Front End part with it.
NodeJS is a javascript framework that allows you to create a server to serve up websites using Express or the built in libraries. It also is capable of building a website with just NodeJS.
You can take advantage of the ability to do server side rendering with a NodeJS server.
https://reactjs.org/docs/react-dom-server.html
There is a ReactJS framework called NextJS tha has server side rendering of ReactJS component.
https://nextjs.org/#features
You could potentially have some areas of your website that are built solely with NodeJS and other pages that use ReactJS and a NodeJS backend. But it is cleaner to use ReactJS for the front-end and NodeJS for the backend.
I'm creating a video game that has single player and multiplayer. The single player is done in C# (Unity), and want to use Gamesparks BaaS that works on Javascript (NodeJS) for their server code.
Since I want the multiplayer server to be authoritative, I need the server code to run Javascript and the client will run C#, which means duplicated code
But, if I can create .NET dlls in Javascript I can reduce code duplication heavily by using those libraries in Unity and using the Javascript code on the server.
Thanks!
If you want to use javascript (and by javascript I mean nodejs), along with c# and communicate between those two, you can use electron-edge. It helps you to run c# code using nodejs through Electron API.
Here is the link of their Github url: Electron-Edge-documentation
You can also interact with dlls, using an creating your application as an electron app. You refer this question where you will find some more details regarding it.
I'm currently learning Angular2 and went through the quickstart and heroes tutorial. I'm always starting these apps with "npm start".
I've created a backend application in ruby on rails, and also have a frontend angular2 app. I do not know how I can integrate the angular2 app within the rails app. Theoretically, I can just put it into the public/ directory to make the JS accessible, but I probably need to convert it somehow so that the links are setup right.
Can anyone tell me how this is done normally?
Thanks a lot
You can do this in two ways as I can see
1 - Add your angular project folder to app/assets/javascripts or in the root in you app and set rails asset pipeline to use it. read more here (for angular1) https://thinkster.io/angular-rails
2 - Running as a separate project and use rails as only as an API. (this is my preferred method) due to following reasons.
this will give a separation between your rails app and angular app. Basically you are forced to implement things in standard api way, like authentication etc. hence overtime you will have a more solid rails api and angular fronted
once you have the separation, you can run these two in different app servers if you wish to. gives better load balancing etc..
You can always replace both frontend and backend with different technologies later, like amber and node since they communicate only via an http api.
So this option will need more time and effort, but, if possible its defiantly worth it :)
Here is my problem:
Customer wants my current web application as a Desktop, possibly Executable but without browser for the Client part.
I looked into 3 of following :
Qooxdoo - Needs browser
Adobe Air - Needs plugin and Runtime
Appcelerator - Most interesting , builds into Native Client
Here are the main questions:
Client side:
What i have read on appcelerator is it builds things written in html and javascript
into native executable, so what i have already written (HTML + Jquery + Jquery UI + CSS) can be built into Native Windows / Linux / IOS executables without changes to current code ?
Server side:
No problem as it returms html and json and decided to keep running on server. But wondering how offline contents work.
I'm not sure this will actually work. From what I understand, titanium appcelerator provides a framework primarily for you to create applications on the iOS and Android platforms. I did see some things about the Desktop apps, but nothing about the application being automagically created from the source when your backend code is python (and web2py to boot).
I think it might be impossible to just drop your web2py app in and get a final product. For one, how will Appcelerator know that a given URL corresponds to a given controller and function? How will it perform searches on objects in your database? Do you expect it to read the DAL(...) connection string and just connect?
If you don't do ANY server-side processing, and don't use ANY datasources except for JSON, then maybe this would work. Maybe. But I highly doubt it will be automatic, or even all that easy.
It seems to me that you would have to hit every page and save the pages as html to a disc, and then drop the outputted HTML/CSS/JS markup into Titanium. But that means that if you ARE processing forms or searches, or doing anything interesting in the controllers, the titanium application will not have anything to process the server-side backend stuff.
That being said, titanium does work with php code, but not perfectly, And I see issues when using frameworks as opposed to raw php.
http://www.flickr.com/photos/funkatron/4011561849/
It didn't work that great, regardless. Titanium Desktop does still support PHP though, but developing an app with a server-side framework like CI is basically not going to work.
There was also something in the docs about processing python code, but all I saw was that you can place python in the "client" end of the HTML using a script tag as such:
<script type='text/python'>
# ... python code ?
</script>
(ref: http://developer.appcelerator.com/doc/desktop/python )
But that's not going to help with a web2py app.
IN SHORT -- I advise you download the app and create a hello world project. Then follow a tutorial on migrating or converting your application to Titanium. You'll probably have to rework a lot of things, and I'm not sure how you'd get the execution environment required for web2py, so you might have to rework some of the basic GLUON code which web2py is built on.
Sorry :(
You can, however, probably find a way to create a Java application that includes a copy of (a) rocket webserver, (b) python 2.5 or greater interpreter (c) web2py framework, (d) web2py application and package all this in such a way that it runs inside your java application (which will run on any platform) and shows an HTML view to the enduser. Then you could maintain it as a web2py app and just copy the app to your java bundle. I'm not sure if that's any easier in the end, but it looks like you'll either have to port to Titanium or Wrap with Java (or another language suitable platform-agnostic language).