I am developing a mobile app with Javascript on the client side and rails as the api.
I am using Monocle by Tapquo, a MVC javascript framework. I need to call my server to retrieve data in json format.
Should I rewrite the model class method using ajax request instead of the default local storage calls so when I create an object, the call is made in the model? Or should I make the calls inside the controller?
What is the convention?
I'm not sure about Tapquo, but most MVC implementations that are network savvy are really MVC-S, where the S is "service". In other words, you implement a service layer in your app that your controller calls to fetch the model that it wants to work with.
Related
I have an ASP.NET Core WebAPP calling WebAPI. The WebAPP uses Azure B2C for authentication. It then obtains a token which is used for calling the WebAPI. This works great. However, there are scenarios where it would make more sense to use a JS framework (e.g. vue/axios) for building the WebAPP page content and calling the WebAPI directly, rather than through the WebAPP.
How could this be achieved? I came up with the following:
I could create a TokenController which would call the ITokenAcquisition.GetAccessTokenForUserAsync(scope) and return the token to the caller. I could then call the TokenController from the JS, obtain the token, and call the WebAPI directly. The token would have to be obtained before every direct JS call to WebAPI. Is this a good approach?
Another approach would be to use the MSAL.js in the JS code but then I seem to have to reauthenticate. Can the WebAPP login be reused in MSAL.js without the need to reauthenticate? If so, how?
I have a web application with a client that receives data from a server. I have the data in NodeJS, but I want to pass the data to a Javascript file. The Javascript file is included in a HTML file, so I can't make the files communicate with eachother.
I am new to NodeJS, so it can be a stupid question, but anyones help is appreciated
This is for a project where I need have a data stream, and I need to pass it into a web application. I tried to pass the data to different page inside my application and then I tried to get that data on that page inside my web application via Javascript, but I couldn't make that work. I'm not even sure if its possible at this point.
Your node server can't communicate with your front-end without a specific way of communication like websocket, you have many other way to communicate with your front-end as node-server, take a look at server send event for example.
By the way your front-end can call your node server more easely with a get request as said #tomerpacific in comment.
For that you have to open a route with your express app. Routing with express
And for call it on a GET request, for that you can use the XMLHttpRequest, and if you have implemented jQuery on your front, you can use Ajax jQuery.
I have a client web application. The user clicks buttons, gives inputs, makes selections, etc... This is all done with Java using the Spring framework.
The client talks to another service that I have built in Java (with Vertx). This service talks to the database, handles caching, and the endpoints return values.
user navigates to web page--->client controller handles request mapping--->
--->request mapping uses controller method to return view--->
--->view's JS makes requests to service--->service returns model data
Now, I like the idea of control that Spring controllers offer. My client's pages use the Spring controllers to return views, and a small amount of model data.
However, what I am doing to call my service is: in my view's JS, I am making AJAX calls directly to the service. I mean, it works, and that is what was suggested for me to do, but I'm not sure if that is what I should be doing.
The alternative would be for my client to make JS calls to the client app's controller, and let the controller from my client app make requests to and receive responses from my service, then pass those responses back to my JS. I feel like this is probably the "cleaner" or "better" way to do this, but I am only about a year into programming with Java and don't know what the best way of doing this is. Essentially,
user navigates to web page--->client controller handles request mapping--->
--->request mapping uses controller method to return view--->client view's
JS makes requests to client controller--->client controller makes request
to service--->service returns data to client controller--->
client controller handles data and returns data to client view's JS
My gripes are that the JS exposes more than I would like it to in terms of the service's endpoints. Furthermore, I feel like using my client's controller to call the endpoints just seems... right.
I'd prefer input of experienced developers on what is right and/or wrong about these design patterns.
I've seen it successfully implemented both ways. Using a client controller is a fairly easy way of narrowing the exposed surface of the API (provided you lock-down access to the back-end services, otherwise you're just wasting your time). This method also allows you to turn the Client Controller into an adaptor to adapt the return values from the API into something more UI-centric (e.g. map codified values into text via an i18n file) and pare down any surplus data before it goes to the client.
However, there's an element of extra work or duplication as well as a performance overhead (hops, marshalling and unmarshalling).
If you ever suspect you're going to expose the underlying API or the client's usage of it is going to grow to the point where you've effectively created a shadow copy of your API, you should just put in place a robust Auth and Auth system to only allow calls from the appropriate places. This is not a trivial task, but would allow you to expose the API to other consumers.
The current and expected future usage of your API (but don't go all YAGNI on this!) should shape your decision. It may be appropriate to have the Client Controller layer doing filtering and shaping to avoid excessive client payload or not if you want the client to have a more transparent representation of your resources.
I ask if there are any way to update an entity using javascript and symfony2.
when clicking on a button, a function in javascript should be called to update the entity in database
I use symfony 2.6
This is called Ajax. Javascript code sends a request (POST/GET/PUT) to an URL (Managed by Symfony), which can answer.
Communication between Javascript and Server is generally done using POST, and data sent back is generally done in XML/HTML or JSON.
There are plenty of tutorial and documentation, for example:
http://api.jquery.com/jquery.ajax/
You can also look at REST, that defines common API on the Server side. There is a module that helps defining this interface with Symfony:
http://symfony.com/doc/current/bundles/FOSRestBundle/index.html
I'm quite new to web applications and have decided to create a single page web app hosted on Heroku.
My understanding of this web app is as follows:
Client side (AngularJs) has input text box, once button press it requests server side endpoint
Server (NodeJs) uses data from client to call external API (e.g imgur API) and returns json
Server processes json and responds to client with information
Client uses server response to render user interface
Main Concerns
Best practices for external API calling: Should I have an API wrapper class that allows me to call custom methods that return specific external api calls?
How should I handle http error responses?: I understand that NodeJs is async by nature and all http calls are done async as well. If there are multiple responses, error or success, how do I go about handling them all without doing a custom set of ".error()" and ."success()" methods for each call?
Furthermore
I cannot seem to find a good reference material for a simple NodeJs back end like the one I described. Please direct me if there are any.
I recommend looking at this Scotch.io article for creating a Single Page MEAN Application:
Setting Up a Single Page MEAN Application Starter Kit