Netrobase CMS Restful API DOCS

4 min read
Cover Image for Netrobase CMS Restful API DOCS

Netrobase CMS is a lightweight inhouse blogging tool. It adopts a headless CMS approach.

BASE URLS:

Auth Endpoints:

  • /auth/ - [GET] Auth Index View

  • /auth/login/ - [POST] Login Route

  • /auth/logout/ - [POST] Logout Route

  • /auth/password/change/ - [POST] Password Change (From Dashboard)

  • /auth/password/reset/ - [POST] Password Reset (Forgotten Password)

  • /auth/password/reset/confirm/ - [POST] Password Reset Email Redirect

/ and posts/ and /posts/search/ endpoints are not authenticated views, the rest are.

Interact with the platform as an admin. Use the above auth endpoints to login or use the /admin/ endpoint. You can create posts, tags, categories and editors (two editors has been created already, see below) in order to test out the platform. The login credentails are Username: admin and Password: admin_netrobase.

API Endpoints:

  • / - [GET] API Index View.

  • posts/ - [GET] View all (unfiltered) published posts

  • posts/create - [POST] Create a new post.

  • posts/search/ - View Sorted/Filtered posts based on the query parameter

  • posts/<slug:slug>/ - [GET] View a post

  • posts/<slug:slug>/actions/ - [GET][PUT][PATCH][DELETE] View, Update or Delete a post

  • categories/ - [GET][POST] View all categories or Create a new one.

  • categories/<slug:slug>/ - [GET][PUT][PATCH][DELETE] View, Update or Delete a category

  • tags/ - [GET][POST] View all tags or Create a new one.

  • tags/<slug:slug>/ - [GET][PUT][PATCH][DELETE] View, Update or Delete a tag

  • comments/ - [GET][POST] View all post comments or Create a new one.

  • comments/<int:pk>/ - [GET][PUT][PATCH][DELETE] View, Update or Delete a new comment on a post.

  • likes/ - [GET][POST] View all post likes or Create a new one.

  • likes/<int:pk>/ - [GET][PUT][PATCH][DELETE] View, Update or Delete a post like.

Use posts/search/ endpoint over posts/, it is more robust with lots of sorting and filtering features.

A User can only have one Like in a Post.

Post Endpoints Sample Usage:

  • posts/: Get unfiltered posts.

  • posts/?page=2: Get page 2 of the unfiltered posts.

  • posts/search/?order_by=created_at: Sort posts by created_at (default) or updated_at.

  • posts/search/?category=my-category: Filter posts by category with the slug "my-category."

  • posts/search/?tag=my-tag: Filter posts by tag with the slug "my-tag."

  • posts/search/?year=2023: Filter posts created in the year 2023.

  • posts/search/?day=3: Filter posts created in the year 2023.

  • posts/search/?month=11: Filter posts created in the year 2023.

The queries could be combined to get the desired set of post: /posts/search/?order_by=updated_at&category=technology&tag=programming&year=2023&month=7&day=15

Post Images and Cover [In Development]:

In the frontend application, when the JSON response from the API is recieved, you can access the cover(contains cover image url) and images (a list of the posts images url) fields to display the images in your blog posts. You would typically use these URLs as the src attribute in your HTML image elements to display the images.

Pagination

The whole endpoints were set up to return 10 paginated resource per page. You specify the page by passing a query parameter to the url. For example BASE_URL/posts/?page=2, this return page 2 which is the second batch of the posts. You can use the next member of the dict to implement the post page next button, this is to say that it's value is a url. View the development api, to get the structure of the posts json and other resources (tags, categories).

// This shows the page 4 of posts
{
    "count": 51, // number of returned resource
    "next": "https://cms-api.netrobase.dev/posts/search/?page=5", // null when there is no other next page
    "previous": "https://cms-api.netrobase.dev/posts/search/?page=3", // null when there is no other previous page
    "results": [
        // the requested resource(s) appears here
    ]
}

Blog Editor:

  • admin/ - The CMS editor can use this route to manage the blog portal. No need to implement the dashboard UI as Django provides an Admin UI out of the box. A group privilege {group: editor} is also in place to limit the model an editor has access to.

Editors Username: editor1 and editor2

Editor Password: blog_editor (Same Password for both editors)

Limitations/Future Features:

  • Comments have no likes

  • Comments have no threaded replies

  • post/comments only have usernames reference, no profile/dp reference.