Best implementation (folder structure) of SPA with Yii2 and AngularJS 2 [closed] - angularjs

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
As you know angular 2 is in beta right now.
Generally is it good to start a single page application (SPA) using angular 2 and yii2 as a RESTful API (for backend services)?
Assuming this:
how could be the structure?
What is the best implementation of this? (with sample)
Update:
Sorry, but I'm not good in English. I think the usage of implementation was wrong. I mean what is the best folder structure for using yii2 and angular 2 as a SPA like this repo.
Last Update:
As #SalemOuerdani told and mentioned I think that this link is my answer. maybe my question is a duplicate! Sorry for that!

The Yii2 quick start example for REST gave those endpoints as example:
GET /users: list all users page by page;
HEAD /users: show the overview information of user listing;
POST /users: create a new user;
GET /users/123: return the details of the user 123;
HEAD /users/123: show the overview information of user 123;
PATCH /users/123 and PUT /users/123: update the user 123;
DELETE /users/123: delete the user 123;
OPTIONS /users: show the supported verbs regarding endpoint /users;
OPTIONS /users/123: show the supported verbs regarding endpoint /users/123
Well that is REST. It doesn't matter which tool or framework to use. You can rebuild the same using Ruby, C or NodeJS and steal being the same app. Just have it in seperate folder or server and call it backend or server while it retreives data from DB or whatever else to answer the previous URI's.
The frontend in this case is the other app built with whatever language stored in a different folder or server that when it does a request to GET /users will expect a json response. when it does some edits on user 123 and send it back to server within PUT /users/123 it will expect the server to responde with a 200 response to know that it has been saved to database or a 422 error for example if validation fails.
My advice is to work with both tools as separate things. I don't recommand changing Yii's default rooting. The commun point between both should be the standards and concepts or architecture you did decide to implement or design for your HTTP requests.
More answers and a valid structure for Yii and angular may be found in the following:
What exactly is RESTful programming?
Yii2 + AngularJS in a single application - how?

How could be the structure?
There are alot of github repo's available for the best structure of angular2. you could refer to those for structure of your app,
this one is good repo i had ever found here:-
https://github.com/mgechev/angular2-seed
here is my repo you can refer to this too...
https://github.com/MrPardeep/Angular2-DatePicker
What is the best implementation of this? (with sample)
For implementation there are alot of tutorials and articals are there on the internet, but i personaly suggest to refer from the
official website of angular first.
https://angular.io/guide/quickstart
http://angularjs.blogspot.in/2015/12/angular-2-beta.html
http://www.angular2.com/

Related

How to deal with authorization/authentication in that case?

Here at work we have a portal with like 6 systems lying under, each one has its own backend API, built with .NET Core, the frontend is React by the way.
The situation :
Today we have a single API that is used for both Authentication and Authorization (i will call it LoginAndProfileAPI) and its is used globally for all of the systems, here's my attempt to describe how it works :
As Is
we have this global,
The Issue :
Now we have a necessity to have local user management inside each system so that the local admins for that system can manage the access level/permission/profiles only of the profiles related to that application, we also need to turn our Auth process a little bit more standard, separating Authorization and Authentication a little bit more.
What would you guys do in this situation, what i came across until now was :
The idea i had, but stil needs some shape
but it kinda looks like a mess tho.
Does anyone have a clue of how can i be more standard with this
Edit :
Would that be best scenario ?
Looks pretty much like a more minimalistic/lightweight approach !!!
#WandererAboveTheSea suggestion about it
(did i get it right ?)
Here is a cleaner image :
JWT Auth Example
What looked kinda odd to me was that it seems like JWT is beeing used for both Authentication and Authorization
JWT is meant to be stateless and lite weight. Your using JWT for authorization is the correct approach.
You can improve on the following part.
After getting the username you are making database calls to get the user profile which you can avoid by adding those details to JWT itself. So that part can be simplified.
Information Exchange: JSON Web Tokens are a good way of securely transmitting information between parties.
Apart from this rest of the design looks good.

Where can I practice DELETE, PUT and POST requests. Do some free API exist that allow to do this?

I do not have experience in programming. Now I try to learn React. I found different APIs provided by companies for free. But this way I can practice only GET requests. Because, no one wants me to delete, add or edit on their servers :)
So my question is:
How front end developers can practice DELETE, POST and PUT requests?
There are a few websites providing sample API endpoints you can perform DELETE, POST and PUT. See 2 of them below.
https://reqres.in/
https://dummy.restapiexample.com/
My suggestion is that you download a local server from MySql and then use your local server along with your IDE and make the requests in your own database

When use a database? [duplicate]

This question already has answers here:
Storing Images in DB - Yea or Nay?
(56 answers)
Closed 3 years ago.
I'm making a web-site for learning-purpose and in this site I'm planning to add some pictures.
My (maybe stupid) question is, when should you use a database for pictures? Like, is there at a specific amount of pictures that calls for a db, or are db's only for storing other types of information? Maybe db's should be used as soon as you don't want to store everything on your computer?
I was linked another page for a similar post below (my post would be a duplicate). That post is from 2008 and is mostly about SQL. Are there any new thoughts on the subject today, and is there any preferred database for storing different types of data?
Thank you
we can divide website into 2 types :
Static website
Dynamic website
Static Website :
which is created using Html , Css , Javascript , Jquery
normally have less number of pages (5 to 10)
it is just used to display information written in HTML page
Example : Simple Website with common pages like homepage,aboutus,contactus, and 2 - 3 pages with simple information
Dynamic Website :
generally no limit of pages
used to load data/information dynamically
which is build using frontend plus backend and database
database : database is used to store values into appropriate table/document
example of databases :
MySQL,Sqlite,Oracle,SQL,PostgressSQL,MongoDB,Redis etc..
backend : it is server side code written to perform CREATE, READ, UPDATE, DELETE called as CRUD operations into Database and other operations using different programming langauges
backend done with programming Languages :
PHP,Java,NodeJS,Python,Go,Ruby ...etc
frontend : it is used to make http request to backend function and display data on page as per data provided by backend
here frontend can be using HTML,CSS,Javascript,Jquery,Ajax or modern
frontend technologies like : AngulerJS , ReactJS , VueJS
Example : Blog Website, Ecommerce Website, and many more ....

How can I send simple variables to a website with Python

Lets say I had a Python script that determined the users favorite fruit, then sent the data:
fruit = apple
to a website named apples.com
How can I do this?
Also, If you can, can you explain the web end of the exchange, or should I make another post for that?
I am not sure which tags to use, so recommendations are welcome.
The question is pretty vague. You could take a look at the request module to send POST request to the website. The data could be enconde in json format. You'll need to have some sort of API on the website to use the received data. You can make a simple app with Flask.

Mobile application backend

I'm currently developing a mobile application that will fetch data from server by request (page load) or by notification received (e.g. GCM).
Currently I'm starting to think about how to build the backend for that app.
I thought about using PHP to handle the http requests to my database (mySQL) and to return the response as JSON. As I see it there are many ways to implement such server and would like to hear to hear thoughts about my ideas for implementations:
1. create a single php page that will receive an Enum/Query, execute and send the results.
2. create a php page for every query needs to be made.
Which of my implementations should I use? if none please suggest another. Thank you.
P.S, this server will only use as a fetcher for SQL and push notifications. if you have any suggestion past experience about how to perform it (framework, language, anything that comes to mind) I'd be happy to learn.
You can use PHP REST Data services framework https://github.com/chaturadilan/PHP-Data-Services
I am also looking for information about how to power a web and mobile application that has to get and save data on the server.
I've been working with a PHP framework such as Yii Framework, and I know that this framework, and others, have the possibility to create a API/Web service.
APIS can be SOAP or REST, you should read about the differences of both to see wich is best for mobile. I think the main and most important one is that for SOAP, you need a Soap Client library on the device you are trying to connect, but for REST you just make a http request to the url.
I have built a SOAP API with Yii, is quite easy, and I have use it to communicate between two websites, to get and put data in the same database.
As for your question regarding to use one file or multiple files for every request, in the case of SOAP built on Yii, you have to normally define all the functions available to the API on the server side in only one file(controller) and to connect to that webservice you end up doing:
$client=new SoapClient("url/of/webservice);
$result=$client->methodName($param1, $param2, etc..);
So basically what you get is that from your client, you can run any method defined on the server side with the parameters that you wish.
Assuming that you use to work program php in the "classic way" I suggest you should start learning a framework, there are many reasons to do it but in the end, it is because the code will result more clean and stable, for example:
You shouldn't be writing manual queries (sometimes yes), but you can use the framework's models to handle data validation and storage into the database.
Here are some links:
http://www.larryullman.com/series/learning-the-yii-framework/
http://www.yiiframework.com/doc/guide/1.1/en/topics.webservice
http://www.yiiframework.com/wiki/175/how-to-create-a-rest-api/
As I said, I am also looking to learn how to better power a mobile application, I know this can be achieved with a API, but I don't know if that is the only way.
create a single php page that will receive an Enum/Query, execute and send the results.
I created a single PHP file named api.php that does exactly this, the project is named PHP-CRUD-API. It is quite popular.
It should take care of the boring part of the job and provides a sort of a framework to get started.
Talking about frameworks: you can integrate the script in Laravel, Symfony or SlimPHP to name a few.

Resources