Client-based API - processing multiple JSONs - javascript

I want to build a special "API".
The API calls other multiple APIs (answer in JSON), picks single parts of the responses, compose it and print out to one single JSON.
I want to compose the different JSON by using a kind of mapping:
e.g. the old data[0].event.title is mapped to the new data.title
I already build a REST API on a Java Server with the Jersey Framework.
My question: Is it possible to build such an API with JavaScript or a client script language to reduce the work load on the server. The server only provides the code.
The client uses the code to "compose the json" as I mentioned above. At the end I want to make a HTTP Request e.g GET https://apirulXXX.de/2/api/composedjson and I want to get the client-processed JSON.
What framework can I use? What is possible?

Related

Is it safe to make a POST request with JSON data using ajax?

I'm working on web application where I need to send some data using ajax with post method. So I have two choices to send data whether in JSON format or query prams. I'm confused which should I use? and is it safe to send data in JSON format?
As #lucasreta mentioned, if you use HTTPS, it doesn't really matter either way.
Both methods are widely used. I know that Google accepts a Post request with query params and responds with a JSON object for ReCaptcha Server side validation.
Sometimes, the decision to use one or the other (or both) is dependent on how easy your chosen back-end technology makes it for you to either parse out query params or serialize JSON.
I will say that there is a general trend in using JSON in the request body as opposed to query params.
I found a couple of SO questions that are more down the lines of what you are asking...
REST API Best practices: args in query string vs in request body
REST API Best practices: Where to put parameters?

How to use javascript code in arduino and assign javascript values to arduino values

I'm creating an IoT project to send some commands to my Arduino board and receive some details through the internet.
After a lot of search, I recognized that the best solution for me is to convert arduino to a web-server and send requests to it.
I designed the showing page by:
GSMServer server(80);
serer.begin();
GSMClient client = server.available();
client.println("HTML CODE HERE");
but I want to use javascript to parse receiving GET or POSTs and assign them to values in my code.
What should I do?
You will have to build upon GSMServer further so that it can handle different requests and respond different information based on the call.
Have you seen https://www.arduino.cc/en/Tutorial/GSMExamplesWebServer
It shows how different calls can be made as well as how a http request can be responded with a html page.

trying to update JSON file in react

I have a JSON file 'DealerList.json' and I can access it from my app by importing it using
import DealerList from './json/DealerList'
let tasks = DealerList;
The tasks here contain the JSON and I can easily access it.
Is there any way by which I can update the JSON back like if I update the values OR if I delete the values. I have also tried require("fs") but that too is throwing error.
The JSON file is present in a folder called json in the React App.
No, and this is a good thing. You do not want any web browser to be able to come along and rewrite files on your HTTP server.
Write a web service which will read and update the data based on HTTP requests (with appropriate authentication/authorization to stop undesirables from changing the data). Then interact with it via XMLHttpRequest / fetch / an abstraction library wrapping one of them (like axios).
(Or use localStorage if you want to store the data on a per-browser basis rather than shared between visitors).

Backend JSON To HTML for Front End

We have a product like Zillow which has all the Active Properties for Sale. We have a spring boot backend that has JSON Rest API to get those Properties that are on Sale.
Our simple front end calls this JSON API and renders the properties for our HomeBuyers.
The problem is anyone can steal our listings and build their website in minutes from our JSON API. So here is what we would like to do. Instead of JSON we would like to send a HTML to FrontEnd. Our problem is how to go about it in most modern/scalabale efficient way..
Some Options:
1) Don't open our JSON APIs to internet but Write another JAVA Service that fronts the JSON API service and translates them to HTML. So our front end calls upon this new JAVA service and not directly the JSON API service..
2) Node JS App which in Backend talks to JSON API and Converts it to HTML while the front end talks to this Node App.. (Are there any libraries that already do this? Have you ever used them)
Any help/options/opinions you provide are greatly appreciated..
You can "secure" your JSON api with an authentification method like JSON Webtokens. That way, nobody who isn't authenticated can use the JSON api. Use Google's Angular JS to render to your website.

Acessing Gorm object in JS

i developed a web application using grails/gorm about traffic reports. Basically, its possible to find for traffic reports like (in road xx there was an accident yyy and the traffic is very slow.)
now i need to integrate the map in the application. My map is in javascript, how can i access gorm objects in js (if it is possible)?
standard groovy i use:
<%
def road1 = packagename.Road.list()
out << road1.name
%>
Can i have the same kind of access in JS ?
typically for this type of thing you make some sort of request to the server, which returns the data to the browser via JSON or XML. If your map is coming from some javascript library, you can use Ajax to query your server for the data. Which JS library are you using? Whatever it is, it probably has a mechanism to make an ajax request -- you would pass the params on the ajax request that the server needs to get the appropriate data, and when the request returns a callback that define will do something with the data.
As a note, its not a bad idea to set up your application code as follows.
You have your domain object, 'Road'
Generate a RoadService, with a method listAllRoads
Generate a RoadController, with an action listAllRoads
The controller calls the service, the service uses the Domain objects to retrieve the list. In your action, you can take the list and render in whatever form you need (json, xml, or as a gsp).
Grails is all about conventions; the above is how you conform to those conventions.

Categories

Resources