Skip to main content

Blog Tutorial

Let's create a Blog API project with Kontenbase.

Video Overview

Expected results

Here are the expected results:

Kontenbase Blog Result 1

Services or REST API Endpoints

There will be some services with their REST API endpoints or functionalities:

Authentication, Users, Articles, and Authors.

We name the services in plural because that's what is usually recommended for naming the endpoints in REST API.

  • Authentication
    • Register new user
    • Login to user
    • Logout a user
  • Users
    • GET Find all users
      • GET Find one or more users with a filter
    • POST Create one user
    • PATCH Update one user
    • DELETE Remove one user
    • DELETE Remove all users
      • DELETE Remove one user by id
  • Articles
    • GET Find all articles
      • GET Find one or more articles with a filter
    • POST Create one article
    • PATCH Update one article
    • DELETE Remove one article
    • DELETE Remove all articles
  • Authors
    • GET Find all authors
      • GET Find one or more authors with a filter
    • POST Create one author
    • PATCH Update one author
    • DELETE Remove one author
    • DELETE Remove all authors

Fields or Data Structure

  • Users
    • _id: UUID
    • firstName: string
    • lastName: string
    • email: string
    • password: encrypted string
  • Articles
    • _id: UUID
    • title: string | single-line text
    • description: string | long text
    • authors: array of author id | link to records
  • Authors
    • _id: UUID
    • name: string | single-line text
    • avatar: array of attachment object | attachments
    • articles: array of article id | link to records

Blog with Simple Service

Create or login to the account

First of all, create a new account or log in to your existing account. Currently, we only support Google Account or Gmail at the moment.

Create a project or workspace

Then create a project or workspace, we can name it "Blog".

Public Articles

This is the dashboard.

Which shows we don't have any service yet.

Let's create a new service called "Articles", and the type is "Public" for now.

It will generate the default REST API with available requests such as GET, POST, PUT, PATCH, and DELETE.

Customize Article fields

Now let's customize the Articles fields so we can have title as a string of single-line text and content as a string of long text.

Create some articles

Alright, time to create some articles by using the POST request.

  • Title: Hello world!
  • Content: This is the 1st blog post content about hello.

Send the request, and receive the response of the created article.

Let's create another one:

  • Title: Goodbye world!
  • Content: This is the 2nd blog post content about goodbye.

For the content itself, you are free to use any format either plain text, Markdown, or HTML. Because the decision to render that is up to you in the frontend.

Find or get the articles

After creating the article, then we can find them with the GET request.

Notice that right now we are only "Authenticated as Public".

Send the request, and receive the response to the articles.

We can also copy the full URL and put it in the browser or your favorite REST API Client to see.

Filter articles

The filter is available so we can find one or more articles with conditions. For example, which artciels have the title or content containing particular text.

Sort articles

We can also sort by ascending or descending, depending on how you want it.

Pagination

Pagination are also can be used if you want to if you have a lot of data.

Update or patch an article

Next, we can also update one of the articles with the PATCH request.

Get the id of the article we want to update, change the fields, and it will be updated.

Remove or delete an article

Let's try to delete one of them with the DELETE request.

Get the id of the article we want to delete, enter it, and it will be deleted.

Closing

And that's it. We made a very simple "Blog" project backend API with Kontenbase. 🎉


Blog with Relational Services

Create new Authors service

Next up, suppose we want to have Authors now.

Create a new service called Authors, but make it Private now.

Customize Authors fields

We can set it up so each author can have name, avatar, and articles.

Author has avatar as attachments/files

The avatar would be an image file, so we can use the attachment field.

This kind of field would be an array of attachment objects.

Author has many Articles

Since we want an author to has many articles.

So the articles field in the Authors service is a link to record to the Articles service.

We can also decide if we want to "allow linking to multiple records", which in this case is yes or true.

Article has one or many Authors

Because the prior link of Author has many Articles, therefore the Articles services automatically had the authors field too.

By default the name is Authors 1 so we can change it to just authors.

Create some authors

Now let's create some authors.

Authors

Create articles with authors

Since we already setup the Articles service and Authors service, linked them with each other, now we can create articles with one or some authors.

Articles

Let's create some more articles with the authors.

  • The rise of Tesla
    • The article content
    • by Elon Musk
  • Story of my life
    • The article content
    • by Oprah Winfrey
  • The beginning of Microsoft
    • The article content
    • by Bill Gates
  • Millennials and YouTubers
    • The article content
    • by Susan Wojcicki

Closing

Finally, now we have the "Blog" project backend API more complete with Articles and Authors. 🎉