Forem Creators and Builders 🌱

Ali Ziane
Ali Ziane

Posted on

Add more properties to the JSON API

I'm developing an Android client using the Forem API. It's just a pet project, so I'm keeping the UI very similar to that of the DEV android app. However, I'm having trouble replicating some of the designs because the API does not seem to return an equivalent JSON response, especially for the comments endpoint.

While I'm a complete Ruby noob, I decided to check out the Forem repository on Github. After digging into the source code a bit, it seems that the comment DB model does indeed have, for example, the body_markdown or public_reactions_count attributes:

create_table "comments", force: :cascade do |t|
    t.text "body_markdown"
    ...
    t.integer "positive_reactions_count", default: 0, null: false
    ...
  end
Enter fullscreen mode Exit fullscreen mode

But looking at the comments_controller.rb file, they are not included in the JSON response:

ATTRIBUTES_FOR_SERIALIZATION = %i[
        id processed_html user_id ancestry deleted hidden_by_commentable_user created_at
      ].freeze
Enter fullscreen mode Exit fullscreen mode

It would be great if the comment endpoint, like the article endpoint, also returned the body_markdown and public_reactions_count properties?

Top comments (1)

Collapse
 
cloneableteam profile image
Cloneable 🇹🇬 • Edited

Awesome!