V
V
vaflya2020-09-22 14:23:17
go
vaflya, 2020-09-22 14:23:17

How to write rest api for kanban board?

Good afternoon, experience on node.js and php.
I wanted to make a pet project kanban board, tell me a popular framework (gorila?) and orm. The base will be Postgres. Perhaps more moments, such as auto-generation of the rest api documentation. In general, we need an Orthodox stack, which is not ashamed to show people. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav, 2020-09-22
@vaflya

On GO, the "orthodox" stack is a standard net/http package + some kind of external router, for example chi , or not http/rest at all, but gRPC (if we are talking about API).
For a database, pure SQL, at most some kind of structure mapper, such as sqlx (you can also use sql builder, but Goland IDE has good support for pure sql).
I don’t recommend ORM, of course there is gorm (it doesn’t generate queries efficiently, N + 1 with connections), it’s enough for small projects, but any ORM can’t cope with complex queries.
I am categorically against ORM, since for all the time of my work on the web, in any project, the weakest link has always been ORM (it hammers with a bunch of database queries, when it’s 1-2 queries in pure sql), or a programmer, instead of writing a query like "SELECT SUM(amount) FROM book WHERE author = 'Petya'", fetches all records and summarizes it in the code (does work for the database + spends database resources on reading data from disk and transferring them over the network).
No need to use frameworks, it will not give experience writing in go (as in most languages).
Go is used where the performance of other solutions is not enough, or multithreading is needed, which the frameworks provide so-so.
I practically don’t use templates in go, I write the front on vuejs and turn to the go api.
There are documentation generators, but I won’t advise here, they need to be tested separately, each has its pros and cons, I myself use a different solution (I will describe at the end).
The most important thing is to quickly understand that you need to write in go like in go, and not as you are used to in other languages, because it does not have the usual classes, strong typing, the process lives a long time and there can be a race condition (state race) when multithreading (the web server is multithreaded), so I advise you to forget about approaches from php as soon as possible.
In my projects (in production), I use go only as a service providing api. Recently started using grpc-gateway(since I use gRPC, but it is also necessary to make the API available via the web), the project allows you to describe everything that is needed in proto files (see gRPC), generate models and wrappers for most languages ​​+ documentation in OpenAPI 2.0. This is not a framework, it's a wrapper over the standard net/http, which immediately validates and maps the data to the structure.
Briefly:
For a beginner, I advise you to forget about frameworks (they will not help in learning) and ORM (not effective).
Use for web server:
net/http - built into go
chi (easier) or gorilla/mux - router
To interact with the database:
sqlx - a wrapper over the standard sql package, but allows you to immediately read data into the structure, without manual scanning.

M
Maxim Korneev, 2020-09-22
@MaxLK

the meaning of the board is that it is a board and nothing is needed to work with it except for itself, a felt-tip pen and pieces of paper. writing a board emulator kills the board idea. although a whole carload of them has already been written ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question