Yii2 Rest API Location

Multi tool use
I needed to know which folder is more suitable to host my Rest API in Yii2 template advanced, backend or frontend.
I also saw some examples where developers created a new directory, called it "api" and programmed the API from there, but I don't find much information by developing from this method.
If you know the most correct way to do it, I would apreciate if you could explain me.
php api web yii2
add a comment |
I needed to know which folder is more suitable to host my Rest API in Yii2 template advanced, backend or frontend.
I also saw some examples where developers created a new directory, called it "api" and programmed the API from there, but I don't find much information by developing from this method.
If you know the most correct way to do it, I would apreciate if you could explain me.
php api web yii2
add a comment |
I needed to know which folder is more suitable to host my Rest API in Yii2 template advanced, backend or frontend.
I also saw some examples where developers created a new directory, called it "api" and programmed the API from there, but I don't find much information by developing from this method.
If you know the most correct way to do it, I would apreciate if you could explain me.
php api web yii2
I needed to know which folder is more suitable to host my Rest API in Yii2 template advanced, backend or frontend.
I also saw some examples where developers created a new directory, called it "api" and programmed the API from there, but I don't find much information by developing from this method.
If you know the most correct way to do it, I would apreciate if you could explain me.
php api web yii2
php api web yii2
asked Jan 2 at 15:48
AfonsoAfonso
83
83
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
That totally depends on your requirements if it is going to be a complete full app or just a single controller with a few actions or a single ActiveController
.
But a good way is to keep things separate just like you are using the advance-app
and you have the backend
and frontend
folders so that you can differentiate the code base, and keep the code in their concerned folders, those folders are actually 2 separate applications
running separately with their own separate configurations i.e backend/config/*
and frontend/config/*
, and can share some common configurations like database and others from the common/config/*
. Same like that you can create a separate application/folder where you can have all the code base and configurations related to api you are going to build.
You can find a very good reference for adding more apps into your existing application by Yii here on GITHUB which will clear your concept about how to add more apps.
Then you can go to this article by Budi Irawan's Tech Blog which uses the advance-app
to add a new application for the API. You will find the directory structure with example models and controllers along with testing them with POSTMAN.
add a comment |
Backend
and frontend
are also just a folder in the Yii2 advance app
with just namespace
different, they are different for our understanding, it is not necessary that you use backend
for backend purpose only.
So for the API
, you can use any of these folders, but it is always recommended to put thing separately like we put backend thing in backend
folder and frontend things in frontend
folder.
It's totally up to you and your coding style.
add a comment |
i prefer putting Rest API into a separate module, for instance into "commonmodulesapi". that way i can "mount" the api in backend or frontend via configuration. Also, nice urls are automatically provided, like /api/<controller>/<action>
(where api
is the name of your module).
One more thing to consider is how to update your api. in case of modules everything is well organized. you could start with "v1" and put your controllers in here, and move up to "v2" with a different set of controllers. so your first api endpoint would read /v1/users
, later on you can additionally provide /v2/users
.
more about modules here
read "URL Rules" here
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009254%2fyii2-rest-api-location%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
That totally depends on your requirements if it is going to be a complete full app or just a single controller with a few actions or a single ActiveController
.
But a good way is to keep things separate just like you are using the advance-app
and you have the backend
and frontend
folders so that you can differentiate the code base, and keep the code in their concerned folders, those folders are actually 2 separate applications
running separately with their own separate configurations i.e backend/config/*
and frontend/config/*
, and can share some common configurations like database and others from the common/config/*
. Same like that you can create a separate application/folder where you can have all the code base and configurations related to api you are going to build.
You can find a very good reference for adding more apps into your existing application by Yii here on GITHUB which will clear your concept about how to add more apps.
Then you can go to this article by Budi Irawan's Tech Blog which uses the advance-app
to add a new application for the API. You will find the directory structure with example models and controllers along with testing them with POSTMAN.
add a comment |
That totally depends on your requirements if it is going to be a complete full app or just a single controller with a few actions or a single ActiveController
.
But a good way is to keep things separate just like you are using the advance-app
and you have the backend
and frontend
folders so that you can differentiate the code base, and keep the code in their concerned folders, those folders are actually 2 separate applications
running separately with their own separate configurations i.e backend/config/*
and frontend/config/*
, and can share some common configurations like database and others from the common/config/*
. Same like that you can create a separate application/folder where you can have all the code base and configurations related to api you are going to build.
You can find a very good reference for adding more apps into your existing application by Yii here on GITHUB which will clear your concept about how to add more apps.
Then you can go to this article by Budi Irawan's Tech Blog which uses the advance-app
to add a new application for the API. You will find the directory structure with example models and controllers along with testing them with POSTMAN.
add a comment |
That totally depends on your requirements if it is going to be a complete full app or just a single controller with a few actions or a single ActiveController
.
But a good way is to keep things separate just like you are using the advance-app
and you have the backend
and frontend
folders so that you can differentiate the code base, and keep the code in their concerned folders, those folders are actually 2 separate applications
running separately with their own separate configurations i.e backend/config/*
and frontend/config/*
, and can share some common configurations like database and others from the common/config/*
. Same like that you can create a separate application/folder where you can have all the code base and configurations related to api you are going to build.
You can find a very good reference for adding more apps into your existing application by Yii here on GITHUB which will clear your concept about how to add more apps.
Then you can go to this article by Budi Irawan's Tech Blog which uses the advance-app
to add a new application for the API. You will find the directory structure with example models and controllers along with testing them with POSTMAN.
That totally depends on your requirements if it is going to be a complete full app or just a single controller with a few actions or a single ActiveController
.
But a good way is to keep things separate just like you are using the advance-app
and you have the backend
and frontend
folders so that you can differentiate the code base, and keep the code in their concerned folders, those folders are actually 2 separate applications
running separately with their own separate configurations i.e backend/config/*
and frontend/config/*
, and can share some common configurations like database and others from the common/config/*
. Same like that you can create a separate application/folder where you can have all the code base and configurations related to api you are going to build.
You can find a very good reference for adding more apps into your existing application by Yii here on GITHUB which will clear your concept about how to add more apps.
Then you can go to this article by Budi Irawan's Tech Blog which uses the advance-app
to add a new application for the API. You will find the directory structure with example models and controllers along with testing them with POSTMAN.
answered Jan 2 at 18:36
Muhammad Omer AslamMuhammad Omer Aslam
13.4k72548
13.4k72548
add a comment |
add a comment |
Backend
and frontend
are also just a folder in the Yii2 advance app
with just namespace
different, they are different for our understanding, it is not necessary that you use backend
for backend purpose only.
So for the API
, you can use any of these folders, but it is always recommended to put thing separately like we put backend thing in backend
folder and frontend things in frontend
folder.
It's totally up to you and your coding style.
add a comment |
Backend
and frontend
are also just a folder in the Yii2 advance app
with just namespace
different, they are different for our understanding, it is not necessary that you use backend
for backend purpose only.
So for the API
, you can use any of these folders, but it is always recommended to put thing separately like we put backend thing in backend
folder and frontend things in frontend
folder.
It's totally up to you and your coding style.
add a comment |
Backend
and frontend
are also just a folder in the Yii2 advance app
with just namespace
different, they are different for our understanding, it is not necessary that you use backend
for backend purpose only.
So for the API
, you can use any of these folders, but it is always recommended to put thing separately like we put backend thing in backend
folder and frontend things in frontend
folder.
It's totally up to you and your coding style.
Backend
and frontend
are also just a folder in the Yii2 advance app
with just namespace
different, they are different for our understanding, it is not necessary that you use backend
for backend purpose only.
So for the API
, you can use any of these folders, but it is always recommended to put thing separately like we put backend thing in backend
folder and frontend things in frontend
folder.
It's totally up to you and your coding style.
answered Jan 2 at 16:55
Vinay SheoranVinay Sheoran
31339
31339
add a comment |
add a comment |
i prefer putting Rest API into a separate module, for instance into "commonmodulesapi". that way i can "mount" the api in backend or frontend via configuration. Also, nice urls are automatically provided, like /api/<controller>/<action>
(where api
is the name of your module).
One more thing to consider is how to update your api. in case of modules everything is well organized. you could start with "v1" and put your controllers in here, and move up to "v2" with a different set of controllers. so your first api endpoint would read /v1/users
, later on you can additionally provide /v2/users
.
more about modules here
read "URL Rules" here
add a comment |
i prefer putting Rest API into a separate module, for instance into "commonmodulesapi". that way i can "mount" the api in backend or frontend via configuration. Also, nice urls are automatically provided, like /api/<controller>/<action>
(where api
is the name of your module).
One more thing to consider is how to update your api. in case of modules everything is well organized. you could start with "v1" and put your controllers in here, and move up to "v2" with a different set of controllers. so your first api endpoint would read /v1/users
, later on you can additionally provide /v2/users
.
more about modules here
read "URL Rules" here
add a comment |
i prefer putting Rest API into a separate module, for instance into "commonmodulesapi". that way i can "mount" the api in backend or frontend via configuration. Also, nice urls are automatically provided, like /api/<controller>/<action>
(where api
is the name of your module).
One more thing to consider is how to update your api. in case of modules everything is well organized. you could start with "v1" and put your controllers in here, and move up to "v2" with a different set of controllers. so your first api endpoint would read /v1/users
, later on you can additionally provide /v2/users
.
more about modules here
read "URL Rules" here
i prefer putting Rest API into a separate module, for instance into "commonmodulesapi". that way i can "mount" the api in backend or frontend via configuration. Also, nice urls are automatically provided, like /api/<controller>/<action>
(where api
is the name of your module).
One more thing to consider is how to update your api. in case of modules everything is well organized. you could start with "v1" and put your controllers in here, and move up to "v2" with a different set of controllers. so your first api endpoint would read /v1/users
, later on you can additionally provide /v2/users
.
more about modules here
read "URL Rules" here
edited Jan 2 at 18:25
answered Jan 2 at 18:12
e-franke-frank
494512
494512
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009254%2fyii2-rest-api-location%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
cn,8R4Pjfpdr8epW6,ilkLvr99JUn9juV5RsRO7NByehOdhjfnB8Vg3488Ul 8wSQMIOeT4DoWUxu2YwWqBForwrJk4Gl4