-1

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!

Community
  • 1
  • 1
Akinak
  • 176
  • 4
  • 22
  • 3
    Questions about opinions are discouraged on StackOverflow and so are give-me-some-code questions. Good questions show some code that demonstrates what you have tried and where you failed. – Günter Zöchbauer Apr 05 '16 at 08:08
  • @GünterZöchbauer Of course, but I just asked for better structure implementation, not the code!! because there are some implementation repo with angular 1 on specific structure([like this](https://github.com/hscstudio/angular1-yii2)), then I asked if there is better structure or no! is it a give-me-some-code question? – Akinak Apr 05 '16 at 09:41

2 Answers2

1

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?

Community
  • 1
  • 1
Salem Ouerdani
  • 7,596
  • 3
  • 40
  • 52
0

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.

Evan Wieland
  • 1,445
  • 1
  • 20
  • 36
Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215