Simba.js: The Best Method to Begin Your TS APIs

This marks the preliminary phase of a sequence of posts the place I intend to debate overarching concepts associated to Simba.js. These embody its utilization eventualities, potential functions, related issues, suggestions, and extra.
One other JS library/framework?
Brief reply, sure. Lengthy reply, properly…
In case you are one thing like me, you is perhaps actually aggravated everytime you wish to begin a brand new JS/TS API. More often than not, you need to configure the identical stuff over and over, making a tsconfig.json, .eslintrc, LICENSE, jest.config.js/ts, Dockerfile, and so many extra relying on how complicated your challenge is.
Again in 2021, after I had simply began programming (I had one yr of expertise or so), I made a decision I didn’t wish to do this once more, so I created a CLI software to assist me make all of the configs information and keep away from the stress of making them manually over and over. That software was very helpful on the times I didn’t should create something manually, nevertheless it was not sufficient for me. Why? As a result of if you create an API (at the very least a RESTFul API) a lot of the stuff you do are often the identical.
You need to config your server, then your database, then add some issues within the center to deal with your small business logic — let’s name it “providers” — and eventually add some routes — “controllers” — to reveal your small business logic by way of some endpoints. When you get to that time, you most likely want so as to add some sort of validation between the request you obtain and the logic you’ve got in your controllers, so you might find yourself including some schemas to validate if the request a person despatched was appropriate, and so forth.
As you’ll be able to see, making a JS/TS RESTFul API is often a really repetitive course of. So I began engaged on creating one thing to keep away from this course of.
I acquired inspiration from many locations. Throughout that point, we used to construct SPAs with CRA, and it was enjoyable. CRA gave you a lot of the instruments you wanted to begin constructing your individual app, however that was for the frontend. What in regards to the backend? I bear in mind we didn’t have one thing like CRA, however we had well-liked full frameworks comparable to NestJS or SailsJS, in addition to very opinionated (or not) well-liked frameworks comparable to Express, koa or Fastify that didn’t present you at the very least a skeleton or fundamental config to start with like CRA used to offer. In keeping with what I bear in mind, there was no center level. You needed to go totally with Nest or go by yourself with plain Specific or Fastify.
That’s how the thought of Simba.js (I didn’t have the title but) got here to my thoughts. I wished a software that gave me a place to begin, so I needed to write queries, controllers, or providers by hand, however I simply needed to observe the skeleton to make it work. I wanted one thing that didn’t really feel like magic (sorry, Nest) the place you simply should import one thing, and that was it, but in addition, I didn’t wish to reinvent the wheel.
I used to be prepared, I constructed a CLI software that allowed me, with just a few keystrokes, to create just a little boilerplate with all of the configuration performed and a completely working RESTFul API, however the title was lacking, after which the thought got here to my thoughts. I named my framework/library after my cat, Simba, the laziest creature I’ve ever met. However so I’m. Why? As a result of I don’t wish to create a RESTFul API from scratch once more.
The objective of Simba.js is to standardize the way in which we create RESTFul APIs. Properly, the truth is, that was the objective. These days, I additionally wish to standardize the way in which we construct GraphQL APIs too. So let’s say that Simba.js goals to turn into the usual strategy to construct TS APIs.
In fact, Simba.js is closely opinionated. I selected the backend frameworks I favored (and likewise extremely popular ones): Specific and Fastify, and likewise the instruments I favored on the time, which had been Joi and Mongoose (at the moment not supported) and a few others. I additionally selected the eslint and prettier config I favored, the check framework, and so forth.
I selected these instruments based mostly by myself expertise as a result of they work very properly collectively, and it was straightforward to mix them in a reusable manner. I additionally suppose this is a superb level to begin. As soon as Simba.js supplies you with the boilerplate, it’s fairly straightforward to govern it and escalate the applying based mostly in your wants. Moreover, Simba.js offers you a lot instruments to help you construct your individual API. You may select:
- Between Specific and Fastify,
- A MongoDB or a traditional Relational DB
- A REST API or a GraphQL one
- To have a GitHub Motion of linting and testing
- Which license you wish to use, and many others.
And don’t forget you’ll not have to fret about these annoying configuration information everybody hates.
Sounds good, proper? Why don’t you give it a strive? Right here is the repo (if you need, depart a star there!) and the npm package. I hope you discover it helpful.
That’s it for now.
Pleased coding!