angularjs with restfull webservice - angularjs

Is it possible to communicate restfull webservice using angularjs.my application located in c://Higi folder and i have created restfull webservice in eclipse now i am using return
$http.get('http://localhost:8080/RestfulAndAngularJS_Server/rest/product/findall')
.success(function(response){
$window.alert('success')
});
code for connecting with restfull webservice it is possible or not

If your http://localhost:8080/RestfulAndAngularJS_Server/rest/product/findall endpoint is accessible in general, then it should be accessible via the angular $http service.
You can test whether the server is up by pasting that url in the browser. Depending on how your server side code is set up with regard to content negotiation, you might get an error back (which error will depend on what you used to build the web service, but at least you'll know that it's up).
If it's up then you should be able to call it from the angular $http service. If not, then make sure its' running by starting whatever server you are using in eclipse.
If you're sure the server is up and running, your call should work. You might also consider handling the error callback in your $http.get call to see whats' happening there.

Related

nextjs authentication (OAuth)

New to next.js/react so a little confused on how to approach this:
So we have an app, that will be built on Next.js..
we will have apis that client-side code will call to fetch server data (my assumption is source-code for these apis do not go to client-browser and stays on node server?)
these apis will call our actual apis,
these will be called by using OAuth2 token received from Azure Apps (clientid/secret)
Is my assumption correct regarding api code not travelling to browser
Secondly can I retrieve application-token (using clientid/secret) using NextAuth?
Thank you
Ok, from my understanding the
/api code doesn't travel to client side (I am using getStaticProps to call services directly rather than using fetch as I need calls to be rendered on server side)
I was able to use #azure/identity to receive token that I need to call APIs hosted outside my node.js

(Access-Control-Allow-Origin - CORS issue when fetching data from 2 URL for promises

So I have promises in AngularJS which fetch data from 2 URLs.
promises.push(loadingJson('example.com/1.json'));
promises.push(loadingJson('example.com/2.json'));
$q.all(promises).then(function(resultList){
}, function(errList){
});
After running the page (using Promises) in web server, it gives error "Origin 'www.abc' not allowed by Access-Control-Allow-Origin." and "XMLHttpRequest cannot load '1.json' and '2.json' due to access control checks".
For Jquery GET method I can use JSONP to solve the error.
But is there a way that can solve it in angularJS promises?
AngularJS is client sided. You can solve your problem server sided here and leave your AngularJS code untouched. You can use cors.
It depends on your web server. For example if you are using express try this package
https://www.npmjs.com/package/cors
and then set it correctly and it will work. (Perhaps you are trying to run server and client on the same host? it is quite a common scenario)

Blocking / Initialization service with angular.js

My apps are using many web services on the intranet, and url-s for those depend on the server environment.
My apps are hosted on IIS, which adds an HTTP response header like this: Environment: DEV, so every web app knows in which server environment it is running, and thus which intranet servers it must use to call all the services.
Each of my angular apps uses a service that issues a simple GET against the app's own root just to get any response with the environment name in it, and set configuration accordingly.
Question:
How should an angular app implement such a service that would execute as the very first thing in the application, and make sure that while it is getting that first response, nothing in the app tries to execute an HTTP request against other services, or even try to use any configuration provided by my environment service?
Is there a way to implement such a service in angular that could block every other service / factory in the application till it is done initializing itself?
I have many other services in the app, and none of them really know what to do till my environment service has finished its initialization.
UPDATE
Looking at it from another angle.... is it possible to implement such an interceptor in angular that could do the following?:
execute an HTTP request and block the app's execution till it gets a response
make information from the response available throughout the app as a service/factory/config.
Angular lifecycle could be one solution. Using the angular.config() phase you could peek at the headers of the HTTP service.
Create a factory called 'httpInterceptor'
function httpInterceptors(siteConfig, $q, $injector) {
return {
response: function(data, status, headers) {
siteConfig.setEnvironment(headers['Environment']);
return data;
}
};
)
Then in angular.config()
$httpProvider.interceptors.push('httpInterceptor');
If you truly want to block the other option is to use UI router resolve property to block routes loading until the request has been made https://github.com/angular-ui/ui-router/wiki you can add the resolve method to the root state.
Resolve
You can use resolve to provide your controller with content or data that > is custom to the state. resolve is an optional map of dependencies which > should be injected into the controller.
If any of these dependencies are promises, they will be resolved and converted to a value before the controller is instantiated and the $stateChangeSuccess event is fired.

angular js how to gat data from using $http

in angular js how to gat data from data base using $HTTP
how to solution my problem give me dital and program dital spat by spat examination and program
You cannot get data from database using $http. You have to make web services in php, django,node etc then you have to call web service using $http.post or $http.get based on method which is created by you.
Web service frameworks are...
http://www.slimframework.com/
http://www.django-rest-framework.org/
using $http service, you can only make http request to http server.In this service you can only mention the path/url of file or api(in case of REST API) from where you have to make ajax call.You can't use sql query from remote database.If you want to get data from database using $http then you can call an API which resides in server.That API will take your request and pass it to Stored procedures(PL/SQL) and stored procedures interact with database with SQL queries to get desired data and provide to API and then API make response with data to you which you can get in success callback.

working with $http.post function

I want to save data using AngularJS and RestApi. I am sending an object in data parameter.
I tried both $http.post() direct method and $http() method , but non of these are working.
Always the error coming is "Method not allowed-405"
I am running on local machine.
Edit:
Eventually by doing some modifications like I specified "localhost:xxx" before the 'api/abc', now I am getting the error as "The requested resource does not support the http method 'POST'".
The reason is that the API you're using does not support POST requests to the URL you're trying to POST to
More info from http://www.checkupdown.com/status/E405.html below
All Web servers can be configured to allow or disallow any method. For example if a Web server is 'read-only' (no client can modify URL resources on the Web server), then it could be set up to disallow the PUT and DELETE methods. Similarly if there is no user input (all the Web pages are static), then the POST method could be disallowed. So 405 errors can arise because the Web server is not configured to take data from the client at all.

Resources