I have a legacy system that provides an api with some queries in rest/json (Delphi) in which I will need to consume this data already available.
Then build an app using angular + nodejs, and I would like my application (client) to communicate only with my web-server on nodejs, and the web-server nodejs communicate with api, I will try to explain.
MyApp -> web-server NodeJS -> api rest legacy
client -> (web-server NodeJS port 80) -> (api rest/json server port 21000)
Any suggestions on how to put this structure together ?? Any help will be eternally grateful.
Thank you
I think that you can definitely do this task without too much trouble, I just hope that I can give you the information that you are looking for. (Please ask so I can update my answer for any more details).
Within NodeJS, you can setup an API pretty easily by using the ExpressJS framework. There are a number of tutorials, as well as documentation online to get started with that. You can create an API endpoint in your node app for each endpoint that your Delphi application has, or just create an API for the endpoints that you will need for your angular app, depends on how in depth you need it to be.
Within each endpoint in your node app, you will essentially want to forward the request to the Delphi app. I suggest looking into the Axios library, which is a promise based request library that you can use. You can extract the parameters that were provided from AngularJS, and simply add those same parameters to your request to the Delphi app.
Finally, based on the response from axios, you will want to return that data to your AngularJS.
I can provide links to examples or code snippets if need be, but I am assuming you already have familiarity with AngularJS and NodeJS, and you just wanted to see a potential system flow. Hopefully this helps.
Related
The bounty expires in 7 days. Answers to this question are eligible for a +50 reputation bounty.
Om Nigam wants to draw more attention to this question.
How do i fetch data from my MySql database as json and then use it in react js...? actually i'm new to React and MySql so i just don't know much about it.. Please help
React is not allowed to connect to MySql directly. We need NodeJs to start a back-end server which supporting HTTP API.
You can watch this video, and try to create your demo.
React Node.js MySQL CRUD Tutorial for Beginners
I agree with YinPeng.Wei's idea for setting up a backend server to retrieve data from database. The majority programming language for backend development have packages or libraries to connect with Database.
A similar question was asked years ago about How to connect to SQL Server database from JavaScript in the browser?. The answer is you could do that but it is high discouraged.
The general idea is to create a simple backend server which responds to your React frontend requests. Backend retrieves data from MySQL via sql query, then serialize searched data into JSON format and gives back to your frontend.
Not sure which type of programming language would you choose for backend development. I would do either one of Python, C#, Java for a quick demo.
Typically, you are using React to connect to another app (backend) via an API e.g. REST, THAT backend is the one who connect to the database and passes the data to your React app.
Your react app doesn't even know there is a database, all he knows is the backend that's feeding him. without him he's just a pretty looking dead app.
now from your backend, you have two ways, using languages built-in driver to connect to your database directly (hand writing SQL statements), Or you may use an ORM, just google "js orm" and you will find many.
As a start, you need to learn more about creating a simple REST API with whatever language you choose, and then simply use fetch("http://example.com/whatever").then(res=> JSON.parse(res)).then(res=> console.log(res))
the code above should show you whatever you see on the screen when you actually visit the URL inside fetch() from the browser, just text.
REST itself is just a way to use HTTP that people like.
the browser itself is just another client (like your React app), if he can do it so does your app.
first, you have to solve the console error of key of react, give the key wherever you
How do I hide an API's secret access tokens in a production build of an app created with create-react-app?
I've visited this question but it does not have an acceptable answer to my question. I do not want to use process.env.REACT_APP_SECRET_VALUE in my app as this variable would be exposed in the client-side javascript.
Given that the production build of a create-react-app app is composed of static files only, the only solution I can think of involves only using APIs that use a combination of public client IDs and some form of backend client whitelisting, IP or otherwise.
Am I missing something here?
Like you already mentioned, you can request an api backend that only returns your secret if it's whitelisted IP.
But still can you be a litle more specific what are you trying to achieve, just guessing but maybe you need to look at direction of some authentication first so after that the user on the client side would be able to do something (see secret).
You're on the right track. If you're unwilling/unable to expose keys for services you're using, you may need to create an endpoint on a server somewhere that you call and have that endpoint proxy the relevant API request. Amazon's API gateway could probably handle this for you.
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html
Good day to all.
I'm new to Marklogic and was able to create a rest api locally on the machine.
Based on the example, it uses curl to send/create document in the database.
My question is, how can i use/utilize the rest api accessing it from another machine or client via javascript (e.g. send data via ajax)? What is the best practice for client-server tier?
A sample code would be sufficient and appreciated.
Thank you.
Here's my first experience with the Node.js Client API and MarkLogic: http://www.tamas.io/2015/02/08/marklogic-and-node-js/ I hope you'll find this helpful as well.
It might be worth reading up on the Node.js Application Dev guide.
The MarkLogic Node.js Client API might also interest you.
HTH!
I am working on chat server so I want to create a server and I have been said to use express and socket.io module. Would someone explain me about these modules and help me making chat server?
When you post questions on Stackoverflow, it is expected that you provide some code that you have experimented with so far. Please refer here for details about how to ask a question.
However, from the looks of it, you seem to be someone who is just starting off with Socket.io and NodeJS. So I'm answering here so that someone else who might also be at your stage can get an idea where to start.
A good starting point for learning how to build Chat applications with Socket.io and NodeJS using Express can be found here on Socket.io's official website
Scotch.io also provides a good tutorial on this here
In a chat application, Socket.io provides an abstraction over the HTML5 WebSockets API on the client side, and implements WebSockets on the server side, where your server is running on NodeJS.
ExpressJS is a Web Framework built on top of Node, that provides you an easier API for building servers, and dealing with requests.
I've googled for few days, some tutorials talking about using ember-cli to build an ember app, but most of them are teaching me to separate the server into two.
That is, one for providing the API endpoint to query the database (with custom express server, mongoDB...), and one for hosting the website (with ember-cli), it means that I have to start two node.js backend servers to serve one website.
Can I do it in one node.js app?
Yes, the only limit to how many "sites" you can run in a single node.js app is based on the hardware of your server. Even the smallest of servers should be able to handle running your api + the website endpoints in one node.js app.
However, what you have isn't two node.js apps, you have an express.js api, and then an ember-cli webapp. It isn't built in such a way that it would be easy to simply consume your ember-cli webapp with your api or the other way around, so i'd have to go with "Yes, it is probably possible", however, good luck making it happen.
I would avoid trying to combine them.