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!
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
I just started coding couple months ago, I just want to get a simple example(such as hello world) on C++ client talk to nodejs server. I ve been searching online but it all comes out of C++ talk to c++ server. If someone can help me out, I would be much appreciate. THX
I have no example. Here is how to handle this in general.
Node.js works under web server. As any web server it communicates with client by GET/POST requests. So you have to take C++ http-library. Using it connect to your web server. Send to the server GET or POST request and take an answer from node.js.
GET/POST requests are very simple, use http-library to form it.
I believe node.js answers using xml/html. So you will have to parse the answer using appropriate library.
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.
I'm currently building a web chat with node.js for the backend. It uses web sockets for the communication between server and client. I haven't worked with node before and I always used PHP/MySQL and Ajax to store and retrieve data. The chat can be compared to MSN etc. with user accounts and contact lists.
I was looking for some tips and frameworks, which could help me with developing a website which heavily relies on JavaScript and which does all its communication via node.js.
What would you recommend to store the data? Mongo db (mongoose? mongo-db native?), SQLite? An easy solution would be appreciated.
Would you send everything via the websocket and would you establish a new connection for every conversation?
Is there a way to get around PHP completely?
Would you recommend the usage Backbone.js or Ember.js?
Thanks for you help!
What would you recommend to store the data? Mongo db (mongoose?
mongo-db native?), SQLite? An easy solution would be appreciated.
I would suggest you to use redis, because it is insanely fast.
> Example of benchmark result The test was done with 50 simultaneous
> clients performing 100000 requests. The value SET and GET is a 256
> bytes string. The Linux box is running Linux 2.6, it's Xeon X3320 2.5
> GHz. Text executed using the loopback interface (127.0.0.1). Results:
> about 110000 SETs per second, about 81000 GETs per second.
As client I would use node_redis
Would you send everything via the websocket and would you establish a
new connection for every conversation?
websockets are not yet support by every browser(pointing especially to Internet Explorer ;)). I think you should use socket.io which supports multiple transports so that it will work in every major browser.
Is there a way to get around PHP completely?
You could get around PHP completely. Use for example express as your web framework instead of PHP
Would you recommend the usage Backbone.js or Ember.js?
Also need to have a better look at both of them.
Use mongo-db or couchDB to store the data.
Establishing a new connection is better than sending everything through websockets and parsing them.
Yes. Use node.js on the server side.
You can try either one of them. Both have their pros & cons.
This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
Remote Database access
I'm developing an app for android which shoult connect itself to a remoe mysql-database.
So far I know what to do to get the app running visually...but how can I transfer the data into a remote database?
What kind of processes have to be developed to get the data into the right shape so that a websserver can translate that and put it into a database?
What do i have to do for getting:
the right structure of the data
transfer/translate/design an interface to bring data to a remote server (--> is it possible to use javascript only)?
What do i have to use? Ajax/JASON etc.
Anyone can help me out on this question of architecture?
You can create some RESTful web services to access the mysql database, then the Android app can call the web service to get or post data to the db, use XML or JSON as the format of data.
It depends on your remote database. If it is CouchDB for example, you just do simple HTTP requests.
If it is SQL you can use JDBC like other client applications would, too.
But perhaps you don't want to have database passwords on your clients. Then you will have to create a web application which is connected to your database. This web application then could provide your favorite (JSON over HTTP) protocol to your android clients.
Take a look at web APIs. Most common is WSDL/SOAP. In regards to the structure, I'd advise you to take a look at JSON. XML works as well, but is pretty redundant. There is also the possibility of using Remote Method Invocation with Java, but that's usually not really worth the effort, I think.