0

I have an existing Zend Framework 2 project. Now I've been experimenting and considering rebuilding the front end to be entirely AngularJS, as opposed to the now with Zend Framework 2 MvC coupled layouts and views. But for that reason, the models and controller with their respective routes exist and they use services that have a lot of business logic.

If I were to add an API to this existing project through Apigility, say, for external third parties to be able to access account information, how am I supposed to do that without interfering with my current controller routes?

Apigility Admin UI automaticly creates routes appending the base url (www.domain.com/[api url]). This does not directly conflict when I have an AccountController with /account routes and an API route that uses /accounts/[:accountId] but mistakes are bound to happen.

I should use a url like api.domain.com, however Apigility Admin UI adds the routes automaticly and has, as far as I have seen, no option to create a subdomain route through subdomain 'api'. Of course I could modify the automaticly generated routes every time I make changes through Admin UI but that seems like a hassle and prone to error.

Community
  • 1
  • 1
Ventus
  • 150
  • 1
  • 12
  • 1
    Maybe you're over thinking this. Each Apigility service lives in a module which has a base route witch distinguishes it. If you add a new service, it creates a new module, e.g. `Api`. Your new Api module can then share your existing models. If you were serious about your existing controllers containing logic, this is a code smell you should fix. Refactor any controller logic into services which can be shared by your new Api controllers and your existing Mvc controllers. – dualmon Jul 29 '15 at 20:53
  • Yes I am aware that every service lives inside a module. That is not my concern. I am just trying to find a way to nicely create different base routes from existing routes (eg /user/ (of my existing user path and its children) and /users/ (created by the Apigility Users service). I would like to not have just a base route, but a hostname with a subdomain as a base (api.example.com/[apiroutes]) route. I didn't mean my controllers had logic itself, just the services and the likes. I misformulated that. – Ventus Jul 29 '15 at 20:57
  • So then this question is really about how to route multiple sub domains into the same project and have different modules handle the routing based on sub domain? If so, I'd simplify your question, as it has nothing to do with Apigility. See http://framework.zend.com/manual/current/en/modules/zend.mvc.routing.html#http-route-types – dualmon Jul 29 '15 at 21:01
  • No, for that the link I mentioned above already gives me the solution. But someone else was friendly enough to give me a proper answer after reading this on IRC. Giving you credit here though, I was overthinking this. – Ventus Jul 29 '15 at 21:06
  • Cool, maybe simplify your question and then document the answer here then? – dualmon Jul 29 '15 at 21:10
  • NB: I think you said you don't want to do this, but rather than subdomains, the Api module can have a base route like this, `domain.com/api/accounts`, which also prevents route name clashes. – dualmon Jul 29 '15 at 21:13
  • I've changed the title and text accordingly. Yeah I am aware of the base route, and currently I am in fact using /api/. But, although argueable practice as well, I might use a /v1/ prefix as well, it might be nicer to use api.domain.com/v1/, is what I thought. – Ventus Jul 29 '15 at 21:19
  • Defining version as part of the route is not preferred by purists. Instead you can use custom Media Type header. https://apigility.org//api-primer/versioning – dualmon Jul 29 '15 at 21:26

1 Answers1

0

While spreading my question around for an answer, someone on the #apigility IRC channel was friendly enough to give me an answer.

I was overthinking this, as dualmon mentioned in the comments. I had thought Apigilty Admin UI was a tool for managing the whole API. nuxwin^ on IRC told me that while Apigility Admin UI does automate routes for you which can be configured with a base url, it's still only meant for development time. It would mean if I were to route my subdomain to a module I could do that after developing the API.

Simple solution, I just had been overthinking that tool demanded me to follow a certain path.

Ventus
  • 150
  • 1
  • 12