Start a Node API in Less than 10 Minutes with Strapi!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everybody this is chris sev with better dev here so strappy which is a node headless cms that i absolutely love just came out with version four really big version so strappy is really cool because it lets us build out apis in less than 10 minutes all without a single line of code so when you talk about jam stack and the javascript world these days you are going to need apis the a in jam stack is apis so let's see how fast we can build out an api with strappy and i just want to show you how cool it is because when you need an api for your applications that you can connect to a database strap is a good choice not sponsored or anything i just really like strappy so let's get into it i'm going to go to their homepage i'm going to click this right here npx create strappy app and they name it my project and we'll keep it and quickstart says let's use sqlite locally when you go to production you can hook it up to postgres whatever you need i'm going to copy that and this is going to preview what strappy is i'll go into item paste that in right there press enter let that thing run so strappy i really enjoy using because of the ability to build out your models let's say we wanted to do a blog in this case we're going to build out blog posts we're going to have users in there we are going to let users edit and create blog posts from the cms strappy is a node headless cms so once you build out your apis you build out your content it gives you a rest api or a graphql api which we can then grab data from using like react or something let's see if strap is done still going all good come on here we go so when you run that command it also runs the develop command which is npm run develop which starts up the dev server so we can start to work with it and actually while i'm here let me open up a new thing right here i'm going to code my project so i'm going to open this up in vs code this is the strappy project and this is you can deploy to github and then anytime you update your strappy dashboard it will update your file system so i want to show you that towards the end of this video let's see this is still running come on okay it's running strappy develop now and there we go it opens up the strappy dashboard and just like that we have a cms that we can use i'm gonna do chris sev chris at better.dev password password and i'll go ahead and create my user and this is the strappy dashboard so it's a headless cms so it gives us the dashboard it doesn't give us the front end it just gives us a rest api or graphql api i'm going to go to create your first content type now a content type is something that we're going to store in our database so we're going to create a new collection type we're going to use posts api id for singular that'll be post api id for plural will be posts with an s i'll click continue and v4 comes with this really nice new ui and i think they did a great job at the design now we get to build out our models for our posts so all of our posts probably should have a title so i'm going to add a new text field call it title it'll be short text and i'll click add another field we'll probably want rich text for the content that works out nicely i'm going to click add another field let's do a number for let's say likes maybe page views you can change out your number format we're going to go with integer here and this is amazing because if you're doing something like this in your own time on let's say node and express or laravel you're building out these models yourself you're building out the database and you're building out your schema but here we're just like clicking some buttons and building it out you can go to advanced settings for this field as well make it required default value let's bring that up to zero i'll click finish right there and now we have the structure of a blog post so we have this here ready to go i'm going to click save it restarts our server okay so let's go to content manager and now we have a nice dashboard to update and create all of our stuff so i'm going to add an entry i can even hide the sidebar right here let me move my face out of the way hide the sidebar title is my first post this is really cool and likes let's push to 10 so i'm going to click save and this by default is in draft mode editing a draft version now we can click publish and now this is going to be accessible from our api so to build out draft and publish versions yourself in your own api not fun so what's cool about this is we have localhost one three three seven let's try to go get this data from our api localhost one three three seven i'm gonna do localhost one three three seven right here localhost one three three seven slash api slash posts and by default you just go to slash api slash whatever you created in your models and now you can access that from an api but you're saying chris we have a 403 which is an authorization error and we don't have access to this resource strappy by default comes with really good security everything is forbidden out of the box we have to explicitly give access to each of these things so i'm going to go to my dashboard go under settings there's a users and permissions plugin and this is all from the docs the docs are fantastic really good docs go to roles and now here's where the fun starts we have a public role which is what we were doing when we did this because we're not authenticated and authenticated role you can add new ones like author i don't know editor i can click public right here and for public users for this post content type i want public users to be able to see them and maybe see one but they cannot create delete or update and it tells you what the url is to api posts id for this one and for this one api slash posts and it's a get request i'm gonna click save go back over here refresh and we should see our post now and it comes in as data and that is an array of objects which is our posts so that's really cool we have an api and we've been able to do it without writing a single line of code we can now deploy this entire github repo wherever we needed to deploy it hook it up to a production database and we have a database cms where we can give our users a nice dashboard where they can update things and let's see in our code check this out if i go to source api post which is the content type we just created and i go to content types schema and once this opens up all of the schema that we just created title content likes are in here so everything you do in the dashboard corresponds to a file in this repo and what's cool about that is that we can break out and let's say we need more functionality than the dashboard gives us we can say let's say oh when i create a post i want to create a slug and the slug is auto-created from the title you can do that by going into your controllers and then adding extra functionality for let's say when a post is created or a post is saved you can add extra functionality so this is a no code solution but you can break out and do code to supplement the nice dashboard that strappy gives you so it would be a low code solution but i'm a big fan of it because look how much strength we just did with zero code and there's authentication authorization built in and check this out there's relationships as well so if i go into content type builder right here and i go into posts i can add another field and these are all the fields we have but down here is where it gets fun we get a relation and instead of posts is related to let's say users right here and we can call this author and a user can have let's see many posts so a user has many posts or you can even do let's say a user belongs a post belongs to many users so that's saying if a post has multiple authors or that user has one author i can click finish click save and just like that we were able to do a relationship by clicking a few buttons i think that's amazing it is a node open source headless cms that you can build an api out in five or so minutes we're just hanging out having fun here so please do check them out again not sponsored just really like strappy i've built out apis like this with node and express it's not fun especially when you want to deal with things like authorization authentication filtering so let's say if you wanted filtering you could do pagination page is equal to one like that so it does pagination for you out of the box really good stuff let's see what else can you do with strappy you can do images as well you can do any sort of api you need to build can be done really quickly dragging and dropping clicking some things congrats to the team on v4 and if you did this video please and subscribe down below definitely appreciate it appreciate you watching here thanks again for better dev this is chris seve
Info
Channel: Better Dev
Views: 986
Rating: undefined out of 5
Keywords: web development, javascript, node, node api, node api no code, node strapi, node api strapi, strapi javascript, strapi api, no code api, low code api, low code javascript, no code javascript
Id: CVELWwVa_0I
Channel Id: undefined
Length: 10min 38sec (638 seconds)
Published: Thu Dec 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.