Amplication: The Ultimate Tool For Learning Back-End (APIs) With TypeScript
I am fairly new to programming.
I started to learn code about a year ago, and completed a few courses with a focus on APIs. When I finished these courses, I tried to write a simple API: a bike rental shop. I did what I was taught throughout the courses, and I wrote a basic, functioning API.
Excuse me, did I say “functioning”? I meant it was a hot, messy mess — practically unusable. I was lost within my own project — not understanding what I wanted to write and how to write it, how to connect objects to one another, how to use my database correctly, and sure as hell not how to manage permissions!
I didn’t know any better, and I didn’t know where to look for help. The internet is so full with questions, answers, tutorials, courses, videos, articles — it was overwhelming for a self-taught new programmer.
But then, I found project Amplication (or rather, it found me).
So, what exactly is Amplication? Let’s get to it.
Amplication is a project. Not just any project, but an OpenSouce project and a website that lets you build your own API without having to write a single line of code. That’s right, you will get an API project, that you yourself make, without having to write any code at all. The concept is called “No-Code” or “Low-Code”, and what it means is exactly that, that you can make a piece of code without writing anything, and this can come to be in many ways. In our case, what you get is a platform, where you can put together like your own puzzle. So I created an API using only Amplication’s very stylish and intuitive interface, and when I was done, I simply downloaded the API as a project folder onto my computer and used it locally, to continue coding there! Not only is this very useful for actual development, but also for learning, which is what I want to talk with you about today.
I believe, that with this amazing tool, you can understand the conceptual building of an API very easily while building an actual API. Amplication will let you build complex, yet basic, intelligible APIs, and give you a great understanding of the creation of Apps, Entities, User Roles, Permissions, how to connect and interconnect them all, and everything in between.
Let me demonstrate. Feel free to join me (the link is at the end of this post)!
Defining our data model
You will start by creating a new App. In the newly created App, you will find a default User Entity and a default User Role. From there — imagination is your limit.
Say we’re making a certain (infamous) bike rental API. We can create an Entity called “Bike”:
We can give it some fields: Price, which we set to a number value that we can limit to a certain max number. Renter, which we can set to the value of “Relation to other Entity”, which we can set to the default “User” Entity. isRented, which we can set as a Boolean value, to indicate whether the bike is currently rented or not. serialNumber, which we can set to a number value. And let’s do a last one, timeOfRental, to which we can give a date-time value. Feel free to add more of your own Fields!
Now that our Bike Entity is all set, let’s create a “Staff” User Role. Now that we have a Staff Role, let’s talk some permissions. We’ll go back to our Bike Entity and edit its permissions. Let’s set the “View” & “Search” permissions for all roles, so both staff and renters (the users) can see & search for the bikes in the system. Next, Let’s modify the “Create” & “Delete” permissions as such: we’ll set it to Granular, and select our newly created Staff role. That means that now only Staff users can create or delete bikes from the system. The “Update” permission will be a little different. We’ll select Granular, and add the isRented Field, and we’ll give both roles permission for only this field, so they can both check the bike as rented or returned.
I believe we did it, we created a very basic and functioning API! Now, we’ll go ahead to the Commit section, and Commit our API, a feature very similar to committing in GitHub. For those less familiar with GitHub and committing, this will “save” our API with our current progress. Simultaneously, Amplication will automatically create a “Build”, meaning it will transform our project to code, and build us an actual, NestJS API project, which we can download to our computer.
Let’s do that.
Get our code
Press the download button next to the Generate Code line, and save the ZIP file. Now unzip it, and open your project’s new directory with your code editor. You’re good to go! Up to this point, we’ve learned how to build and actually built the API conceptually. Now comes the practical part, where we will learn the code behind our API, and how everything is connected! To begin, I’d recommend that you just go through your new project, and inspect the code — it will speak volumes! Notice that the code is fully Typed, just like a good ol' TypeScript project should be. You’ll notice that our Entity, Bike, is in the project and has its own directory. In it, you’ll find quite a few files, so take your time and inspect all of them, but focus on the Service, Module, and Controller files. These are the files that define our Bike entity, how it behaves, and how it communicates with the server and database. Make sure you take the time to inspect and understand how these work — they’re important. You’ll also notice other files and directories, such as the User directory, which is our User default Entity, and our App Module .ts file, which defines the connection of all of our project’s assets.
After you’ve done all this, try to add some stuff to the project with code, I’m sure you can do it! Maybe a bill calculator, or a special rental deals mechanism (3 bikes for the price of 1, or a week’s rental for the price of only 5 days!). Now that you’re acquainted with an API, both conceptually and practically, I’m sure you can make it.
So now, hopefully, you understand how this truly incredible tool can be used for your studies, and how much you can benefit from using it. And hey, if you run into any problems with it, or any troubles at all, Amplication has a great and embracing team and community, and an awesome discord channel!
GitHub — feel free to star!
Also on Twitter & Facebook.
Obligatory disclaimer: I became a GitHub contributor to Amplication, and I know the people there. They’re really nice!