DEV Community

Sam Wicks
Sam Wicks

Posted on

Week 2, Day 1: Building a database & more

I considered looking into CMS add-ons for my existing portfolio site so that I could migrate this blog over there, but then it hit me: this is a perfect opportunity just to build my own blogging backend and work on my (slightly rusty) backend skills a bit more. So I started this week out with a plan to build a database and API to post my own blogs to my website.

Hopefully I'm not in over my head.

The Plan

I started off by creating a brief plan of what my API was going to look like. Foolishly, since it turned out I should probably have focused first on what my database was going to look like before worrying about the API endpoints.

This is why I need more practice.

The plan is pretty simple anyway, for now. This is only a week long project, and I generally only spend ~3 hours on coding a day, so I'm not trying anything ambitious off the bat. I just want something that will take my text and allow me to post it to my site in a blog-reader format.

For now it's just a two table SQL database: one table for articles, and one table for topics. The second isn't even strictly necessary, but I may expand the scope at some point, and anyway it should make it more easily browsable.

The endpoints are going to be similarly simple:

  • GET /topics
  • GET /articles
  • GET /articles/:article_id
  • POST /articles
  • DELETE /articles/:article_id

The dreaded DELETE

And of course, as soon as I wrote DELETE, my mind exploded. I forgot that I'm going to need some authentication for this whole thing, so not just anyone can come in and start deleting my blogs, or posting random stuff to it on a whim.

I can't remember if there was much in the way of authentication on the test project I did in Northcoders, but since it was only a portfolio piece I wasn't too worried at the time. I don't think we created any endpoints that could even be used maliciously.

So this is going to be a fun experience in learning about authentication. It's only a personal (though professional) blog, so I'm not super-duper worried, but it's definitely something to concern myself with, especially as I make it so public.

Copying and pasting

I only started setting up the database today, but so far it feels like a lot of what I'm doing is just copying what I've done before, and it's taking me a little effort to accept that. Logically it's the most efficient way to do this: no need to re-invent the wheel after all. But it also feels like cheating, like I'm not teaching myself anything or showing new skills.

I can justify it to myself in any number of ways: revising old techniques that I've forgotten, practicing those techniques, using them for a more practical purpose; but ultimately, it's something I just need to get over. It's not cheating to work in the most efficient way possible, and it's not even plagiarism if I'm copying my own work.

Anyway, those are just a few of my random thoughts starting this new blog project. Hopefully by the end of the week I'll be able to link people to my own site, or if not I'll have most of it done to finish next week.

Top comments (1)

Collapse
 
idlemuse profile image
Justin Dee

You should continue this!