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 purposes, related issues, suggestions, and extra.
One other JS library/framework?
Brief reply, sure. Lengthy reply, effectively…
If you’re one thing like me, you is likely to be actually aggravated everytime you need to begin a brand new JS/TS API. More often than not, you need to configure the identical stuff again and again, making a tsconfig.json, .eslintrc, LICENSE, jest.config.js/ts, Dockerfile, and so many extra relying on how advanced your undertaking 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 need to do this once more, so I created a CLI device to assist me make all of the configs information and keep away from the stress of making them manually again and again. That device was very helpful on the times I didn’t must create something manually, however it was not sufficient for me. Why? As a result of whenever you create an API (a minimum of a RESTFul API) a lot of the belongings you do are normally the identical.
You need to config your server, then your database, then add some issues within the center to deal with your corporation logic — let’s name it “providers” — and at last add some routes — “controllers” — to reveal your corporation logic by means of some endpoints. When you get to that time, you in all probability want so as to add some type of validation between the request you obtain and the logic you’ve in your controllers, so you could 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 normally a really repetitive course of. So I began engaged on creating one thing to keep away from this course of.
I received 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 start out 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 in style full frameworks equivalent to NestJS or SailsJS, in addition to very opinionated (or not) in style frameworks equivalent to Express, koa or Fastify that didn’t present you a minimum of a skeleton or fundamental config to start with like CRA used to offer. In line with what I bear in mind, there was no center level. You needed to go fully with Nest or go by yourself with plain Specific or Fastify.
That’s how the thought of Simba.js (I didn’t have the identify but) got here to my thoughts. I wished a device that gave me a place to begin, so I needed to write queries, controllers, or providers by hand, however I simply needed to comply with the skeleton to make it work. I wanted one thing that didn’t really feel like magic (sorry, Nest) the place you simply must import one thing, and that was it, but additionally, I didn’t need to reinvent the wheel.
I used to be prepared, I constructed a CLI device that allowed me, with just a few keystrokes, to create slightly boilerplate with all of the configuration completed and a completely working RESTFul API, however the identify 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 need to create a RESTFul API from scratch once more.
The objective of Simba.js is to standardize the best way we create RESTFul APIs. Nicely, in truth, that was the objective. These days, I additionally need to standardize the best way we construct GraphQL APIs too. So let’s say that Simba.js goals to change into the usual strategy to construct TS APIs.
In fact, Simba.js is closely opinionated. I selected the backend frameworks I favored (and in addition highly regarded ones): Specific and Fastify, and in addition the instruments I favored on the time, which had been Joi and Mongoose (at present not supported) and a few others. I additionally selected the eslint and prettier config I favored, the take a look at framework, and so forth.
I selected these instruments primarily based by myself expertise as a result of they work very effectively collectively, and it was simple to mix them in a reusable manner. I additionally suppose this is a superb level to start out. As soon as Simba.js offers you with the boilerplate, it’s fairly simple to govern it and escalate the appliance primarily based in your wants. Apart from, Simba.js provides you a lot instruments to assist you to 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 need to use, and so forth.
And don’t forget you’ll not have to fret about these annoying configuration information everybody hates.
That’s it for now.