Azure with API for WPF and javascript - php

I want to create following project :
Server application hosted on Azure - it connects to databse via Entity framework and gives and API for anyone who want to connect (but with account stored in SQL database)
WPF application - it consumes server methods, objects etc.
Web app (php & javascript) - also consumes server methods and object etc.
IMPORTANT : I have only azure student's subscription and I want to hold onto it - buying anything else is out of the question unless it has strong argumentation.
I figured that to do this I have to create REST Web API because I have no other choice to connect to server than via HTTPWebRequest (because I want to have the same API for WPF nad web app).
My question is : does better solution exists?
I think I can create different API's for desktop client than web app but I have no idea how to do that. Whould you be so kindly to show me other way?
Why dont I want to have this solution?
Reason is simple. For big databases and slow internet connection it would take ages to download whole data in few seconds. As far as my knowledge goes there is no lazy loading in REST thus my WPF application's thread reponsible for downloading database would freeze for a big period of time.
If my question is too broad please leave a comment before you put up a flag.
Also, any tips regarding my project design are well appreciated.

Different APIs for Desktop and Web: this can be done easily enough. Assume you have a class library to contain your business logic (domain stuff). Create a web api project that makes use of it, then create yet another web api project separately that also makes use of the core models. When you deploy, deploy each separately to a different domain/subdomain (I'm unsure if you'll require further Azure resources for this, but consider api.desktop.myapp.com and api.web.myapp.com... no real technical reason why you can't do it that way, though for architecture reasons I'd avoid it (it's really coming close to if not definitely is duplication of code).
Same API for Desktop and Web: you stated that you thought you'd have to do this differently for the desktop and web, specifically because of the resource usage on the server. I disagree here, and think you should implement some standardized rate limiting into your API. Typically this is done by allowing only X amount of resources to be returned in a single call. If the initial request asks for more than X limit, an offset/nextID is returned by the API, and the client submits a new request noting that offset/nextID. This means you have subsequent calls from the client to get everything it needs, but gives your server a chance to handle it in smaller chunks (e.g., check for rate limits, throttling, load balancing, etc). See the leaky bucket algorithm for an implementation that I prefer, myself: https://en.wikipedia.org/wiki/Leaky_bucket)

Related

API - WebSite communication. Should I duplicate logic?

I have been looking for the answer for this question but it was a bit tough for me to come up with the query (question) itself. So if there is already good answer for the below question i would be very grateful for the link.
Let's assume I have an e-commerce web site and an API endpoint for future calls from mobile apps. My question is: should I duplicate logic for querying let's say product for product page on website or should I consider website as an API client and displaying product info by making CURL? request to API.
I suppose I should stick with last one. But I am concerned about making extra curl(TCP/IP) request within script. Will it be significantly slower for the overall response time? Are there any other "patterns" I am not aware of? Thank you.
Sites are on same server but API uses Phalcon PHP and website uses regular PHP
Duplication is definitely the wrong thing to do.
Technically, you have three options:
move the shared business logic to a separate repository and reuse it in both project as private composer package
use cURL/socket wrapper library to access the API (probably using Guzzle)
make public calls to the API using JS (preferably via fetch)
Each of these was drawbacks, so your choice would depend on which option hurts the less.
The shared library would have the best performance, but it would complicate the deployment process and there will be situations, when those applications (site and api) will have contradicting requirements. The problems are organizational.
Internally calling the API server over HTTP will make the site be a lot less responsive (since the TTFB will be a lot longer), but it would let you leave the API code completely unchanged.
Having it all in public comes with security and authorization problems. But, depending on how you expect the mobile API clients to be made, this could be seen as future-investment. But it will require substantial development time and someone who is skilled with javascript (maybe even with JS frameworks), since your website would have to be heavily altered. Most development-intensive option.

I am using Laravel in order to make a DBMS for a social network. I need it to make an app. can anyone tell me how? i cant find anything on google

Using Laravel for PHP and DBMS. How do I make an app? (for social networking).
I have googled most of the things but I am really an Amateur and need help.
There are many kinds of apps, so before you start to work on your app, you need to carefully determine what exactly you need. You could write desktop apps for various operating systems, or native mobile apps, or hybrids, or a web application... You name it. Anyway, Laravel is the server-side and it should be as agnostic to the apps as possible. You need to create an API and handle the following things:
CRUD for the database
session (log in, log out, register, password change, user settings)
logical API functions
file transfer protocol usage
push notification (if needed)
As per your requirements, you will need to implement the server-side API in Laravel, which is a PHP-based framework and use an RDBMS, which could be MySQL, SQL Server, Oracle, or a NoSQL database, for instance MongoDB.
Before you implement any apps, you should have a proof-of-concept for the API. You should not invest too much time working out the details of the API, as when you are going to work on a real app, you will notice things to be changed anyway. The API should be accompanied by a playground for testing, maybe a very small app without design where you could send requests to the API. Or you can implement a WebSocket API to have a single, duplex connection. It is up to you.
As about how to write an API, there are many tutorials.

Pros and Cons of using API instead of direct DB Access

I found myself in several discussions throughout the week regarding a web application under development and whether it should leverage an API that is being created.
Here's the situation. I have a PHP MVC web application with a MySQL DB as well as several mobile apps all being developed in house. For the mobile apps we're building a rest api. The big question is why should my PHP web application now use that rest api? I've always expected the use of an API to be for third party systems that need to interface with my database or for systems built on a different technology. The web app is certainly not a third party system and the services are in PHP. If the API is on a different server than the web app then I guess it could be considered a third party system... which has not been decided yet.
To me, it just seems strange to leverage the API for the web app especially since the APIs services are going to be limited to about 50% of the functions available in the web app leaving me to build the other 50% that would be unique to the web app. I also foresee a performance hit to the web app stepping through the service layer rather than just accessing the DB directly. On the other side I see more maintenance having a code base for my web app hitting the DB and similar functions built into the api for mobile apps.
Has anyone found themselves in a similar situation and can provide some technical pros and cons to why I should just use the API or can point me to a solid case study?
Pros:
What if one day you decide to move the backend app to another machine? With an API, your app code won't need to change.
What if one day you grow, and need to scale to 10000 backend apps instead of 1? With an API, your app code won't need to change.
What if one day you decide to swap out MySQL for Mongo? With an API, your app code won't need to change.
^ Enforced separation of concerns between data access layer (DB) and application
Cons:
More code up front when writing the app layer
More incremental work when you need to support a new app layer feature that your API doesn't support yet
To me, the pros clearly win.

iOS app tweaked for server connection

I'm currently developing an iOS app and have reached the point where I need to implement a server back-end in order to support the core functionality.The app is built in a way to store certain questions locally (Within the app) and pose the questions to the app user. I need to tweak it such that it retrieves the question from a remote server. Furthermore, the question will reside in a specific folder within the remote DB. So the app will have to fetch the questions from the appropriate folder based on user login.
I have zero server experience and am need of some advise as to where I should begin with this. I would like to know if there is a template spec for this kind of task. With a template spec, I can hire a programmer and talk intelligently. Please help!
Here is a number of solutions:
1) You can use other services that provide backend functionality with REST API (as #Niklas Hein mentioned), it calls BAAS - backend as a service, such as Parse (but Parse is closing his service in one year), BaasBox, etc.
2) You can use CloudKit. This is service created by Apple, where you can store app data in the cloud, with authorization, requests, admin panel, etc.
3) Create you own back end. Here is a large number of languages and web frameworks, so php is not the only one solution. Ruby on Rails, Python Django, NodeJS, and many others on your choice.
There are plenty of BAAS (Backend as a service) provider, like Parse or Firebase. You might want to have a look into them. (Although Parse is going to shut down.)
Another simple way is to look into PHP Laravel.
Laravel is a great Framework which makes it really easy to set up a backend.
Have a look at Laracast

API for android/iphone app towards database and Oauth 2

My client wants an android app and an iPhone app. Is it a good solution to make a php based api that both of these apps can use to talk to the server.The API will be used to access the database and to authorisera through OAuth and some other non-database functionality.
Will there be an significant performance loss with an api instead of a direct connection to the database?
There might be some problems with PHP, which, in general, isn't really good in handling a few hundred connections at the some time. Anyway, I would highly recommend you to use some sort of API which filters the input it receives instead of letting anyone connect to the database, otherwise it might be empty within the first few hours of your apps launch (aka this is a HUGE security risk!).

Categories