SOAP Web Services in NativeScript - javascript

I am new in nativescript app development, I want to use SOAP web services in nativescript, i.e how to implement SOAP request & response in nativescript. Please give me suggestions, didn't find any way to implement SOAP, all search results are implemented in JavaScript code.
I do open github issues, please check - https://github.com/NativeScript/NativeScript/issues/2284
Thanks :)

Well, their is no built in soap handling. However, you can make you own in a couple steps.
NativeScript has built in http requests, and XMLHttpRequest and Fetch; this means you can query and receive back data you want from any service url. http://docs.nativescript.org/api-reference/modules/http.html, https://docs.nativescript.org/cookbook/fetch, http://docs.nativescript.org/cookbook/http
In addition, their is a third party plugin called nativescript-apiclient which makes it easier to deal with http requests with changing parameters. (i.e. http://somewhere/getdata/{token}/{data} where you can just pass in a token and data value...) See http://plugins.nativescript.rocks for different plugins available.
NativeScript has a XML parser built in, Soap responses are typically XML based. So you can easily instantiate the xml engine to parse your soap requests (http://docs.nativescript.org/cookbook/xml-parser)

Related

Prevent calling django-rest-framework APIs programmatically

I'm using django-rest-framework, which accepts API requests from frontend javascript. My frontend javascript and backend django APIs are hosted on the same apache server and are within the same domain.
Is there a way by which I can ensure that my APIs are accessible only via the frontend javascript and not via curl commands or any other programming methods ?
I'm not sure about that, the nature of an API is making it accessible to those who have the key and correct way to request information but there are other tools to achieve the same effect if you're only wanting your db accessible from your site. Take a look at django ajax https://github.com/yceruto/django-ajax it works by throwing a decorator on a view which returns a json response. I've found it to be a very helpful tool.

C# Api to Appcelerator app in Javascript

I have made a very simple Web API in C# which does all the functionality required and have also made a simple User Interface in Appcelerator (Java Script). My task is to connect these two together so the app has the functionality of the API. I believe I must use JSON to communicate between C# and Java Script but I'm not sure how to do this.
Can anyone help or point me to the right direction?
Thank you
You can write your own API implementation in javascript that talks to your restful service via http calls.
Also, I recommend taking a look at this project here: https://github.com/viezel/napp.alloy.adapter.restapi which can save you a lot of time doing so.
The language in which your web API (service) is written is irrelevant to the question. You can use Ti.Network.HTTPClient to connect to any web service.
You just need to know what requests the API requires and how it responds. Most APIs nowadays use REST JSON, which means you request via an URL with optional body (for POST/PUT calls) and the response is in JSON format which you can parse using JSON.parse

Can AngularJS be used without a REST API?

When I am creating a simple website with node.js I am fine with using the view engine (eg. jade) and controllers that provide data to it (eg. simple todo list). However, if I decide to add AngularJS as the client framework then it seems that I must implement REST API on the backend to get data from it. Almost all examples I see online with AngularJS have this basic architecture: client (angular) communicates with the server via REST API.
Can AngularJS be used without REST API and if so should I do it or should avoid it? Are there any recommendation/best practices for using AngularJS without REST API backend?
Absolutely. Angular can still do a lot on your site even if you never utilize the $http service to talk to your server. You can still take advantage of the utilities for helping out with managing your DOM.
That said, most modern apps need to get data from the server. There are tons of reasons why you might need to do this. For example, if you had users that needed to sign up then you'd need to store their username and password somewhere. That somewhere would be in a database that only your server can access. Then your server would provide some URLs that you can talk to via Angular's $http service.
If you do have an app that makes calls to the server but you want to turn off the network communication for testing, you can mock the $http call responses. Angular provides an $httpBackend for that exact purpose. You can use it to set up dummy URLs that pretend to respond to your $http calls so that your $http calls don't know they aren't actually talking to a server.
authRequestHandler = $httpBackend.when('GET', '/auth.py')
.respond({userId: 'userX'}, {'A-Token': 'xxx'});
Perfect for testing your code without a REST backend during testing.
REST which is short for Representational state transfer is basically things or resources instead of actions. Yes AngularJS can be used without REST API.
You can use nodeJS for your restful API and AngularJS as your javascript framework.
Even without a restful API AnguarlJS is a very strong tool to use in a project although to use it to it's full potential (fully scaled web app) then you would need a restful API.
use $http for not RESTful API
use $resource for RESTful API

How to do OAuth authentication via AJAX / jQuery?

I've worked a bit with Twitter web API, I know it works with OAuth, I've consumed the API using a python library. I've also tried a bit of Instagram API using a Java Script small library.
I know those perform web REST requests in the background, authenticating first and then querying requests as I code.
However, what if I want to perform the requets using jQuery $.ajax from a web application?
I've read some docs and sites and it seems it's just possible. Like only ajaxing to the API routes, starting with the authentication route.
But, how does this process work? I mean, I query by AJAX to the auth route and then how do I keep track of that authentication. How to keep that communication? Will the redirect URL play its role then?
Reading this site for Instagram API I start getting a clue about it, but got the doubts mentioned above.
I want to perform all AJAX requests in the Java Script server background (I'm using node.js), assuming I will provide my apps OAuth in the $.ajax. Is that OK or I can actually code it on client site keeping my OAuth tokens save?
And, if it's concern of this same question, when it comes to bytes (pictures, sound, etc) how to catch the response from API.
Okay, if I understand what you are trying to do is to make an Ajax call from a web page to the Twitter API and post/retrieve tweets and other info from Twitter.
Since the release of the API v1.1, Twitter has deprecated the v1.0 API and one of the major changes in 1.1 was Authentication Required on all Endpoints
And to do this from JavaScript and jQuery is quite possible (albeit very cumbersome, difficult and requires the use of many 3rd party JS libraries to HMAC Hash your data and keys and calculate content lengths on the client side before making your Request. Twitter API does not support CORS but does support JSONP for these kind of Ajax requests. But this is not recommended - since doing this on the client side will require you to have your Twitter App Access Keys - Private keys - embedded in your script files - which is basically a big NO-NO. And hence a server side solutions to generate your oAuth tokens is recommended. But once you have achieved that, it may be easier to get the token on your script and make Ajax calls using that from the browser. But I haven't gone that far in my research.
Also, this is based off of my research in Mid 2013 when my Twitter Ajax widgets stopped working because of this change and I gave up trying to fix it using that route after I realized it would compromise my security keys. Things may have changed since then.
If you are still interested to find a solution, this walkthrough would be a good place to start learning about Twitter's oAuth and how the Access Tokens are generated: https://dev.twitter.com/docs/auth/oauth

Consuming an authenticated RIA Domain Service via JSONP

I'm writing an HTML5/JavaScript application that needs to consume data from an existing WCF RIA Services Domain Service. Requests will always be cross-domain so I have added a JSONP endpoint onto the service using the solution I posted in this stackoverflow question.
Using jQuery.ajax() I can successfully retrieve data from the service when authentication is off. With authentication on I get this error:
Cross domain javascript callback is not supported in authenticated services.
This is by-design behaviour so I need a workaround!
The possible solution I'm looking at is to try and use OAuth. My current thinking is to use the JavaScript library and DotNetOpenAuth code referred to on oauth.net. I'm hoping to implement the service in a seperate server instance with OAuth authentication (instead of forms/windows) and tack on the relevant request headers to my jQuery calls.
So my reason for posting is, does this sound reasonable and is this the best approach? And if so does anyone have any experience, tips or samples they want to share? :)
Thanks,
Chris.

Categories

Resources