Which proxy to use in sencha touch 2 when i have restful api - api

I am trying to make a sencha touch 2 mobile app. I have a restful api in server and i want to consume that in my mobile app. Which sencha proxy should i use (rest, ajax, jsonp)? Rest and ajax has issue with cross-site domain issue, so jsonp can be the solution. But how can i send jsonp request to rest api if i have parameters?

You can use REST proxy if your services truly follows REST standards because that way proxy can provide you out-of-the-box functionality to operate on models.
Regarding cross-domain issues, please note that the way app behaves in desktop browser is different from its behaviour when it runs in phone so you are not forced to use JSONP if you don't want, AJAX can also work for you. Its good if you can use JSONP but please keep in mind its limitations of having no support for HTTP headers and other useful methods like POST, PUT & DELETE.
Please go through this for more information : How to use json proxy to access remote services during development

Related

Can I use NextJs API routes to handle both web and mobile app?

I want to create web app in Nextjs and in the future mobile app in React Native. But I am confused what api to use. Do you think that the Nextjs api can handle both web and mobile apps? Is this possible and is it good idea at all? Should I use PHP backend for that? Thank you very much.
With the assumption that you are talking about API Routes :
I would ask you that you think through the scale of your web and app. If this is a simple web/app that you do not expect to grow much - The NextJS API which is similar to standing up an nodejs express server is not a bad option.
Remember a few considerations when designing this API
You may have to distinguish the request origin (web/app)
CORS may have to be customized - Next exposes this
You could set an app specific route to ensure isolation or use headers to distinguish behavior if your application bifurcates in the future.
These concerns are shared even if you made a PHP, ExpresJS or any other API middleware.
Once you are past all this, i would ask you to consider
Using a GraphQL server like Apollo that works nicely with Next and is custom built for this purpose..
Evaluating API Gateways for security and scale.
You don't use any external tools at all.
Next JS has serverless model. So, you don't need to mess with BE.
You can create a number of API routes you want. in /pages/api folder. You can even split like /pages/api/desktop and
/pages/api/mobile folders.
You connect your database (MongDB, sql etc) via /middleware/your_file.js. Here is example for MongoDB
If you like, you can even add some security (ex: Auth0, next-auth
etc) to secure your API routes created in /pages/api folder. Example for Auth0
After, you can access you data througth API calls. Very good!

web api support in all type of apps

We want to use Web API for inter-operable purposes. i mean our web api can be exposed and used in different type of apps ( Asp.net mvc, php, android, windows store/phone and ios).
We are not using wcf and prefer web api. Will it be a good choice ? we just need http and https.
Please guide the best.
if you only need support http protocol yes, web api is an excellent option, web api has a lot of features that can help you to build robust http services, and yes, I mean is a good choice.
be careful when you build yours web api service, use best practices, security in your service, and think in rest architecture, not only simple web services and you will have a true rest service
If you want to read more about this (to have a good base, not the final or only way to do this), see the rest maturity model and json api.
WCF is the best way when you need to support others protocols that only http.
Regards

Semantics3 API with AngularJS Authentication

I am in the process of learning AngularJS. I am building a mobile first application using bootstrap 3.1.0.
Basically I want to consume the Semantics3 API and display the products in a list. How can I do this when Semantics3's API needs authentication via OAuth. I already have my API key and secret, but I do not know how to successfully make the call to the API from my Angular controller.
At the moment my code looks like so:
savvyShop.controller('ProductsCtrl', function($scope) {
$scope.apiResult = $http.get('https://api.semantics3.com/v1/products?q={"cat_id":13658,"brand":"Toshiba","model":"Satellite"}')
});
Unfortunately, there would be no way you can do this from the client-side (via AJAX). This is because you're trying to make a cross-domain request, which all Javascript engines do not allow. In general, if the API provides a JSONP endpoint, you could use that to make cross-domain requests. However, Semantics3 does not have one.
You could write a server-side script that effectively acts as a proxy between the client and our Semantics3 servers. It would basically pass on whatever queries you send to our URL, receive the results, and send it to the client. That way, you can use $http.get in AngularJS to run those queries.

Creating a Web Proxy for Mobile Clients (HTML5 Web App)

I'm currently developing an HTML5 mobile web app for Blackberry using WebWorks that interacts with a 3rd party API.
Unfortunately i can't use the API directly from the mobile app due to the cross domain requests constraints, so i'm considering the development of a Web Proxy that interacts with the API and serves the web app.
Since I've never done such thing i would like to get some recommendations, i'm going to use Microsoft technologies (.NET) to achieve my purpose.
I'm thinking about a WCF service that makes all requests to the API and the mobile client connects to the WCF service to get the data, but i think i'll have the same cross domain requests limitation anyway so it might not work.
First, check with your third-party API provider if they support CORS. If they do, you can get around the same origin policy restrictions. Assuming they don't, you can create a facade service using ASP.NET Web API instead of WCF. ASP.NET Web API is designed from the ground up for creating HTTP services for broader reach and there is no SOAP involved.
From your ASP.NET Web API, you can make a HTTP call using HttpClient and simply pass the request to the third party API and echo the response back to your app. As you rightly said, the same origin policy restrictions will apply to this case as well but you have more control over the server side. You can implement CORS in ASP.NET Web API and that way your BB WW app can still call your web API despite being in different origins.

Crossing sub domain ajax calls

We wish to build a web app that will consume our REST API and looking for a way to circumvent the Same Origin Policy security feature.
We have a REST API which is served from api.ourdomain.com from SERVER_1.
We have a Web App which is server from dashboard.ourdomain.com from SERVER_2.
The Web App communicates with the REST API using ajax calls that include GET, POST, DELETE and PUT requests.
At some point in the future, we might consider allowing 3rd party sites to access the API from their own sites and domains.
Due to the Same Origin Policy security feature of the browsers, these requests are not allowed.
We are looking for ways to circumvent this.
Solutions we have encountered:
Tunneling the requests through our proxy. This will slow down the app and requires more resources.
JSONP - Will only work for GET requests. We do not wish to overload the GET requests with post/put/delete capabilities.
Using an iFrame with document.domain set to the same domain. Will only work for sites under ourdomain.com.
Frameworks such as EasyXDM. Seems like a good solution.
Thank you!
I don't know EasyXDM but I have the same architecture you are talking about in more than one application. We use your suggested solution (1). In my opinion proxying the requests through a common subdomain is the cleanest solution. I don't think that this is a performance problem. Many sites use something like nginx anyway to do some sort of reverse proxy (as cache). You could easily tunneling your API through http://[yourhost]/api and the rest of the HTML, CSS and image resources through other paths.