DEV Community

Cover image for Advices for building a Rest API
Fris
Fris

Posted on

Advices for building a Rest API

Chosing the language:

languages

If you're already familiar with a particular language then just go with it, but what i recommend is Go, because Go was built for this purpose and you don't need any framework when using Go.

Other language you can use:

  • PHP (Laravel/Symfony/Zend)
  • Java/Kotlin (Play/Spring)
  • Ruby (Ruby on rails)
  • Python (Django)
  • Javascript (Node.js)
  • C# (.NET)

Database:

database

There are multipule choice, i recommend maria-db which is basically mysql but whatever you chose, don't use SQLite3 for this purpose because you'll find yourself trapped when you want to host your back-end in multiple servers.

To manipulate it there are two choices, Whether you use an ORM (i recommend GORM for Go) or raw sql which is faster but harder for beginners.

Security:

security

If you're planning to do explicit stuff like editing database or returning private data, you should use a private key that is passed throw header. Examples of errors that beginners usually do:

1)

When making the "forget password" request, never return the key to front-end and just store it in the database.

2)

When making the "login" request, make the front-end send the email/username and password to the back-end and in the back-end check if the user has made too many login attempts and then return as less informations as possible if the login is wrong.

3)

Use jwt. It's super important to check if the token is right or not when manipulating the logged-in user's data.

Data:

It's important to return a data that can be read by the front-end, most used are JSON (recommended) and YAML.
But you can simply all this query stuff for the user and the owner by using a query language like GraphQL which is trusted by many entreprises.
GraphQL

Contribution:

Make you sure to give advices in the comments too!

Top comments (4)

Collapse
 
patzistar profile image
Patrick Schadler

These days it is very simple to create a Rest API. Nearly every programming language allows doing so. I have recently written an article about how you can do it with dotnet core. However, there is also one for dotnet class, but they differ not really much. The benefit of using dotnet core simply is that it's running on every operating system and C# is widely known.

Although, if you just start programming maybe nodejs with express could be the easiest solution, but Go and Python is easy to learn too.

patrickschadler.com/creating-a-res...

Collapse
 
ogfris profile image
Fris

yeah i recommended Go because it's super fast and easy to learn.

Collapse
 
timorthi profile image
Timothy Ng

Could you elaborate on what you mean by "Go was built for this purpose"? I don't know much about Go so I'm curious to hear your opinion.

Collapse
 
ogfris profile image
Fris

Go was built mainly to be a back-end language with super fast compilation time by google to replace C++ which was taking ages to compile. (From what i read on some books)