You’ll need something to route contexts, typically an extra like XRouting which routes based off http_host, base_url, and site_url context settings. At that point you’ll be able to access resources in your second context.
MODX_API_MODE does nothing.
If you can be more specific about what you’d like to do, perhaps we can help guide you in the right direction.
Hi, Mark. There used to be an API mode, but I see in the docs maybe it’s been removed.
I’m trying to have an API mode context for doing API only operations through ajax calls. If I hit a script on the web context I get HTML encapsulated responses that are not compatible with the JS parser. It’s expecting raw JSON responses.
Maybe I need to downgrade MODX to a previous version that supports API mode?
I don’t quite understand how routing has anything to do with putting an entire context in API mode. I was previously able to simply specify that I wanted MODX_API_MODE to be true, then the MODX engine would only return raw responses without HTML encapsulations.
Right, so I pasted that code into a snippet and I get an HTML encapsulated response, because the context loaded is web…so I fail to understand how it’s useful unless you create a folder and file outside of MODX.
The point of contexts is to switch the operating mode, right? So, do I switch the operating mode to API mode on the fly at the context load event? That’s how it should be done from a proper software engineering perspective.
That snippet lets you specify which context you load.
e.g.
$modx->initialize('othercontext');
Contexts can represent different websites, or variations of websites such as different languages.
You’re talking about HTML encapsulation, so I assume you’re attempting to get the output of a particular resource? If so, you can change the way it’s served via the resource content_type field.