XF 2.1 Create new API endpoint?

Hello people,

I recently installed XF 2.1 on my test board because of the new API.
Currently I have an external site that utilizes data from XF, it just queries the database now
but I thought it would be nice to replace that with the API.

There isn't an endpoint for that currently, so it'd be worth making a specific suggestion about it. It might appear in a future build (though the API is also extendable if you have need for a particular endpoint).

In this post Mike mentions that the API can be extended, I would like to add my own endpoint for something not present in the API.
I've been digging around in the code a bit to see how stuff is routed but I can't figure out how I would add an endpoint.

So my question is, can anyone show me a basic example on how to do this? (in the form of an add-on).

Looking forward to replies.
 
Creating an API endpoint isn't really different than creating a new public/admin route, if you've done that before. API routes are just a specific route type, so defined in the "routes" page of the development section of the control panel. You'll see all of the default API routes when you click on "API" at the top.

The default API controllers are in XF\Api\Controller and hopefully that should give you a baseline of where to start.

(The latest version of the RM and MG both have full API implementations too.)

If you have more specific questions, I may be able to help.
 
All API responses will be returned in JSON format, except in cases where a binary file is specifically requested (such as when downloading an attachment). Errors will always return a response code in the 400 range.
Is it possible to get an 404 though the route is correct?
I have added a scope league:read
a route like for threads and rescources, but for leagues
i have added api/controller/league
I have added api=true for some fields in the entity
i have not added a relation, because i dont know for what (i just need data from this table)
i have not added the typical api-function found in entity threads/resources
i have not added anything else

I can fetch a thread, but get 404 for my api_class league.php

How can i view the route itself or test if the api_class is reached?
 
Top Bottom