Get the *name* of a forum through the API



  • I'm trying to build a little wrapper around the API (the one you get at by prefixing a URL with api/). Is there any place in the API where I could find the title of a forum?

    By the "title" I mean the bit after the halfpipe in the page title. For this, it's "NodeBB", for this forum it would be "omz:forum," etc.

    I could search the HTML for a <title> tag and then find the bit after the |, but using a full-fledged HTML parser to find the title of the forum seems rather like cracking a nut with a sledgehammer, especially when I'm using a JSON parser everywhere else. I'd rather not add another huge requirement to my project for such a simple task.

    Does the JSON API expose the forum title anywhere? If not, where can I easily find this information? I'm just resistant to the idea of pulling out a huge HTML parser only to find the title of a forum...

    Also, an API documentation would not be unappreciated, even an auto-generated thing that describes the fields for each of the types of API pages.


  • GNU/Linux

    I don't think it's provided in any api route.
    You could either write a small plugin (exposing response.locals.config.siteTitle thought), or use a regex like JSON.parse(/^\s*var config = JSON.parse\('({[^']+})'\);/.exec(response)[1]).siteTitle where response is the HTML string of any page.



  • Yeah. Thanks for that. I forgot to mention, though, it's not just parsing the HTML of a page that's sub-optimal, but also downloading it in the first place.

    This project isn't meant to only work on one site, otherwise I would just hard-code it, so a plugin won't work. Is there any public file that might expose response.locals.config.siteTitle without my writing a plugin?


  • GNU/Linux

    Oh, I found out there is a route: /api/config ;) https://community.nodebb.org/api/config
    Pretty straight forward...


Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.