Karl_T Posted April 6, 2019 Share Posted April 6, 2019 I would like to make a template for API Endpoint, i.e. www.domain.com/api/. The issue is that most of my sites are multi-lang. The URL will become like www.domain.com/en/api/ or www.domain.com/de/api/, which make some issues when calling ajax from the frontend. What I want to achieve is to remove the language part of the URL, which is exactly the www.domain.com/processwire/ looks like. The admin URL does not contain the language part. I look into the Admin's edit (The admin root), it does have the language name enabled, but its children, e.g. Admin>Pages, all the language names are showing /processwire/pages, instead of /en/processwire/pages/. I want to replicate this to /api/ and its children pages, which are also api endpoint like /api/login/. I have tried to disable the template multi-language support, but, unfortunately, the /en/ part is still there. Link to comment Share on other sites More sharing options...
dragan Posted April 6, 2019 Share Posted April 6, 2019 17 minutes ago, Karl_T said: I would like to make a template for API Endpoint, i.e. www.domain.com/api/. How is your API setup? Do you have this one single endpoint to retrieve everything? You could allow URL segments in your home (root) template (if you need just one, define only one and name it "api"). Then you would have to include some logic in your home.php template to handle the API requests. if($input->urlSegment1 == 'api') { // ... } else { // regular display of homepage } https://processwire.com/docs/front-end/how-to-use-url-segments/ 1 Link to comment Share on other sites More sharing options...
Karl_T Posted April 6, 2019 Author Share Posted April 6, 2019 2 minutes ago, dragan said: How is your API setup? Do you have this one single endpoint to retrieve everything? I want multiple api endpoint setups and have their own templates. I want to use them by some custom modules, each having their own endpoint under /api/. And I don't want to mess with other templates. Thanks for your suggestion! Link to comment Share on other sites More sharing options...
Karl_T Posted April 15, 2019 Author Share Posted April 15, 2019 I found the solution. By amending this line in LanguageSupportPageNames module, we can set any template to bypass the language segment of the URL. It would be great if this can be editable in the module setting. Right now, we can just copy the module to /site/ and override the module inside /wire/. Hope this help somebody looking for the same api approach for multilingual sites. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now