Ajax call by HTTP request in angular 2 - ajax

I am trying to load some user data from database to my angular 2 page. I am doing the angular 2 as separate application and using ReST APIs for get data. My back-end is designed using spring and spring boot and maven tool. So when I am using my angular 2 page, is it possible to load my data from spring boot micro services using Ajax call? Angular 2 supporting Ajax call for HTTP request?. If possible, can anyone share any reference link for exploring the Ajax with http request in angular 2?

So when I am using my angular 2 page, is it possible to load my data
from spring boot micro services using Ajax call?
Yes, that's what Angular is built for, single page applications which calls back Restful services for data. Only thing is I wouldn't phrase it as AJAX call (sounds like an old school :) ) I would rather call it as REST service call.
Angular 2 supporting Ajax call for HTTP request?
Yes it does, that's what Angular is built for
If possible, can anyone share any reference link for exploring the
Ajax with http request in angular 2?
Any sample Angular App with a backend will serve as an example. You will be able to find lots of examples by just googling it. Even if I am providing the code here, it will become irrelevant overtime as angular library itself is evolving. So, I would say, wise thing to do is, check their official website (angular.io, not angularjs that's angular 1.X, ancient stuff) and look for http call examples (eg. tour of heroes project).

Related

How to use REST API with FaunaDB?

I have created a collection in my Fauna database. I also made an index that returns all the data in that collection. I want to know if there is a way to get JSON REST API to work with this data. What I mean by this is I want a URL that I can 'GET' using XMLHttpRequest and then parse into JSON.
You might say that Fauna is "HTTP native". All of the language drivers (JS, C#, Python, etc.) are built on top of http requests. That is, there are no special connections or connection-pools to maintain. You can get pretty far with using the JS driver in the browser, for example, without using a server.
But to answer your question more directly, there are many ways to serve a REST API, and it is going to depend on how you want to serve the API.
Examples
AWS
Here is a blog post on how to set up a REST API with AWS App Runner, for example.
https://fauna.com/blog/deploying-a-rest-api-with-aws-app-runner-and-fauna
Vercel and Netlify
There are also some example apps on github that demonstrate using a REST API with
Vercel:
https://github.com/vercel/next.js/tree/canary/examples/with-cookie-auth-fauna
Or Netlify:
https://github.com/netlify/netlify-faunadb-example
Both of which host serverless functions for you to create a REST API.

Content Negotiation fails on using EDMBuilder Web Api 2 (ODATA service)

I am currently working on an OData Web API 2 service using EF6 with a code first approach. My controllers all derive from the base ODataController. I have made use of Ninject for DI and Owin.
I am trying to expose OData but for some strange reason on using the EDMBuilder, content negotiation fails even on a browser, giving the HTTP 406 error.
Content negotiation works when I use the ODataConventionModelBuilder, but I cannot use this as I will not be able to use breeze's client side features.
Wondering if anyone has come across such an issue before while using the EDMBuilder.
Looks like this is documented :(. It is there in the Breeze documentation at the following link with a suggested workaround: http://www.breezejs.com/documentation/odata-server

Is AJAX a Rest api

Recently I have been working on Ajax. So according to me AJAX displays content in HTML using XML. But now does this mean it is a Rest api.
AJAX is a set of (typically) client-sided web development techniques, while REST is an architecture style for sending and handling HTTP requests.
So you can use AJAX to send RESTful requests.
A REST API is typically not implemented using AJAX, but can be accessed by an AJAX client.
There is plenty of information on both AJAX and REST (API) on the Internet. It should be easy to find.
Using REST we can do operations (PUT,POST,GET,HEAD) but by using AJAX we can only retrieve data from server side , AJAX can be a part of REST but REST can never be AJAX
http://rest.elkstein.org/2008/02/ajax-and-rest.html

Is it worth writing a SPA if I have to make 2 API requests instead of 1 each time?

I want to build a SPA but, for security reasons, I can't make the REST API calls directly from the browser. Instead, I have to make an ajax call to the server and then, have it make the REST request. If I was not doing a SPA, I could just have the one request on the server-side. And each of my pages ends with a POST request so I have to do this every time I switch routes. Do I still get the benefits that come from a SPA if it doubles my requests?

Caching dynamic REST content in Cherokee

I'm developing a backend server for a mobile app using Cherokee + PHP-FPM + MySQL. I'm providing a RESTful API using Luracast Restler 2.
How do you cache dynamic content so that, for example, once a client has requested a list of items through the REST API, this list (in JSON format) is cached for every other client request until the content validity is set to expire? A global cache mechanism for all clients?
Restler 3 final release will have server side caching support built in the framework itself. Currently you have to implement it on your own within the api method

Resources