Splitting web-app and mobile-app request in Yii2 - json

I created a restful web-app platform using yii2 framework. It is working with no problems using a browser. Now I'm developing a mobile-app with angular and ionic and I'm searching for some guide to help me splitting the request from browser and app. Using the browser the web-app is configured to have a html view response, how can I detect a mobile-app request to change response in JSON format in each controller/action?
It's my first mobile-app development.

I just fighted this same war this week and I ended up splitting the folders and generating a new yii-app with fresh controllers just for the api.
I tried creating the api folder inside the web backend project, but I had to much problems with redirections, and as I was working from Android emulator fueled by Expo it was almost impossible to reach the api inside my localhost from outside.
At the end in the API REST you just reuse the database connection, rest of files are new. So there is no much to win in placing it in the same folder/project.
By the way, read this documentation: Implementing RESTful Web Service APIs in Yii2
As a code example you could check my yii2 web app: https://github.com/jvidalv/fempoble
And the api that works with the web: https://github.com/jvidalv/api-fempoble

Related

Connect to MySQL using Ionic Framework without api layer

Is it possible to connect to a MySQL database directly from an Ionic application without an integration/api layer?
All the answers I found online suggest to create API in php or nodejs, but I would like to develop a sql client and the whole point of the application is to be able to make queries directly from the client device.
I cannot use the node mysql library from client side.
I am using Ionic 6 React.
No, as noted by Mostafa Harb, you cannot directly access a MySQL database in the cloud from a device. You'll need to use some kind of API.
The basic flow:
Ionic app authenticates to the API if necessary.
Ionic app uses Axios or Fetch to use the API to query the cloud database.
The API returns the response in a format the Ionic app understands.
The good thing about Ionic is that it is mostly framework-agnostic, so you can use any API you like.
Personally, I use Drupal, which is a PHP-based CMS that has support for providing access to Ionic via REST, JSON:API, or GraphQL (or a mix of the three).

Can I use Electron JS to convert my web app to DESKTOP app

I have a web app developed using..(PHP,MYSQL,HTML,CSS,JS,AJAX,Datatables, bootstrapjs)
Now, I want to make a desktop version of the same app, and I came across electronjs.
The problem is I dont know whether ELECTRONJS will support all my requirements.
A breif of my requirements:
My app is responsive using datatables.net library including EDITOR for displaying the data .
the datatable plugin requires ajax calls to some API (Which I developed with PHP and hosted on a server)..
but now I want to even do all the DB Operations with electronjs so that my app can work offline.
I am not sure if I can do that with electron
- calling an API (created by same app) from HTML/frontJS
- the API Returns Json data
- the Front JS displays that data on front.
Kindly let me know if this can be done with electronjs,
Well, basically yes. You can build a desktop app like this.
But you wont be able to run it offline if it depends on a server sided API. If you can rewrite your backend Code in JavaScript and use a SQLite DB instead of a MySQL you can run this as electron App.
Keep in mind that your business logic in the frontend can always be abused because it’s not hidden from the user.
FYI: Electron only runs a browser inside it’s own App container. So there is actually no crucial difference between Browser or electron App.

Azure blob access from Html web app

I have a html Web App running off of Azure. I'm trying to figure out how to write and read to a blob from there. I understand I will need a Shared access key, connection string, use a HTTPS and/or HTTP request, use CORS, but now I'm just trying to fill in some blanks about how to set up the endpoints and if I need something in the back end of the web app. How can implement setting up the endpoints with the CORS? Do I need to set up a logic app? What else do I need to set up with the Web App? Will it be better to set up on a Virtual machine? Thank you in advance.
Jonathan
There are several web apps tutorials used with blob storage. Some tutorials i'd highly recommend are as below:
Gallery Photo Web App tutorial:
Provides an example with sample code on how to use a web application with Azure blob storage
Using Azure storage with hosted Azure Web App:
Provides an example on how to integrate and use storage with Azure hosted Web app, including the source code.
Video tutorial:
Video Tutorial showing the use of Azure web App and Storage operations.
These should get you started.

Authentication in HTML5 + phonegap application

I'm building an application on HTML5 + Jquery and REST services at back-end . This application is meant for Desktop users and mobile users. So we are building the mobile version using phonegap. this application is a secure application and needs login screen. but now am in fix how I can achieve this.
1. If i Move the application to ASP.Net MVC then I can't create build using phonegap.
2. For phonegap i found http://www.raymondcamden.com/index.cfm/2011/11/10/Example-of-serverbased-login-with-PhoneGap but i think this is not suitable solution for desktop users
You can secure the server side using the authentication technology of your choice and then make your AJAX calls to the rest services pass along the credentials.
For example, if you wanted to write your service using ASP.NET MVC, you could protect that using something as simple as HTTP Basic Auth and then pass along a user/pass string in your request.
To achieve the login screen, you can write a dummy controller method which your login screen can call just to check if the authentication is working.
If you want a sample ASP.NET MVC backend with a PhoneGap front-end using jQuery, then I have some sample code up on GitHub and a blog describing building the application

framework to be used for UI of node.js backend

I am trying to develop an application using node.js.
Since the same application can be accessed from a mobile device sometime later, it is expected that the APIs will return the json data, and not forward the request to a page after setting the appropriate request parameters.
I am mostly a Java backend guy and a newbie in the UI frameworks(including javascript with just basic knowledge).
I was wondering which UI technologies should i use for the UI? Should i go for plain HTML or php or anything else? Also, will the other UI Application be a webapp and deployed probably in a web server?
Started to use the express module for node.js, and it is awesome. It provides jade(and from which the basic UI can be created very easily) but i have not had the chance to see much into it. Also if i start to use jade, i guess in my app.js file, i will need to forward the request to a page, and not return json data, which i want to avoid.
Can someone suggest me which UI technologies should be the way to go?
The UI is supposed to be quite rich, and with lots of functionalities.
Thanks
Tuco
I would definitely recommend using express.js. As you mentioned you can render jade templates and this will display to the user as html.
You can also send plane old JSON data to the client by using the res.json() method made available with express.
Backbone is a client side framework where you can make single page web applications, and all the html templates are rendered on the clients machine rather than on the web server. Data is persisted to a backend database by using a RESTful API and the following ajax requests. GET, POST, PUT and DELETE.
Later down the line you can use this RESTful API for your mobile app.