Say Goodbye to Backend Coding with PocketBase CRUD!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys in today's video we're going to see a pocket base an open source back-end server that is rated in goldlink and it is just a single file that you can use to create a rest apis for our next small or mid-sized project and we can use it in any kind of Frameworks that we like such as annual react UJS flutter or anything else we're going to the documentation here in the documentation we're going to find uh download links for the pre-built minimal pocket based application and depending on your system you're going to download any of these so as I'm on Windows I have just downloaded this one here and the thing here is just after downloading you get a an archive file and that you have to extract and after extracting it for example I started it here you just have to open a terminal and navigate it to this folder here so as as here suggested so it is pocketbase serve the command run our server and we're going to start in seconds here so I have navigated to the pocket piece I'm gonna run this command hit enter and our backend is running so let us see the folder here uh we have this pocket base and license and the things that we just that we get when we when we extracted it and also we got this data folder that is going to store a database and uh let's say file system for uploading our files here it is using a database in a file and it is MySQL MySQL Lite so uh it is powerful to run mid-size applications or let's say with thousands of connections and I've seen it somewhere like in the frequently asked questions here and you can see the scale abilities and things and even without optimizations puckerbies can easily serve 10 000 plus concurrent and persistent real-time connections on cheap VPS so uh it is really powerful for this small kind of application so after we run that command let's return to it uh we see a rest a we can see a rest API here Euro and we can see an admin UI here the first thing that I suggest is to go here to click on the rest API or actually to the UI here and here we'll get a login page or actually a register page then we can we have to create an account for us so for a testing purposes I'll just create a added come and I'll just add a password let's see test one two three four five or something or from one key doesn't matter it has to be minimum 10 characters okay and we can say create a login and after doing that we get a UI for our rest application so uh what is interesting here uh we don't have any users here and we're going to create some user for our application let's say so I'm going to add a new username here and I'll call it my name Adnan and I don't need an email I'll just add a password test one two three four okay let's verify let's say and I can see okay I don't need to upload an author and now I'm gonna create a username here so I have a user here and this is like collection with users we could create anything we need here for example uh I'll I'm gonna create a roles here collection of roles for example and here I'm gonna create a new Fields here let's see uh it's just going to be a name of roles so I feel this name and it is not empty it is unique okay and we can just say done and create here and now I can create a new role here let's say admin and another one here let's see user doesn't matter you can create as many as you need here rules so it is as simple as that here and this is like uh some kind of my setup and here in users I would like to add a new field that is actually uh relation to our collection of roles and we are setting for example we are just right now selecting a single row or we can select multiple rules doesn't matter and we're going to create a display name of uh roles here and it's not not empty okay and we can just call it role okay and now done save changes and we can see that if I if I click here I can edit rule to for this user here I'll click open picker and I'm gonna select the user let's see it is user here save changes and now we have a role user for this uh for this account here so this is some of the first steps let's say that I'm going to use how am I gonna I'm gonna use this pocket base and now uh we're going to create a products collection let's say we have a store and we want to see I want to create the products and into that products we're going to add new fields so it's plain text it's uh products and we can add some limitations or anything and I think your ex patterns oh and I'll just say that it is not non-empty field so it cannot be empty and also we're going to add the let's say description description and it's not empty done and also uh we're gonna see here let's say is its price or anything let's say what number else quality price I mean Max and is non-zero or doesn't matter I can create it and also what we can add it is some kind of Boolean it is just like is it active or available okay create and now we have created collection of products here the important thing here to note is that after creating collection we have to go to the settings this gear button here add collection and now we have API rules here so what does this mean this API rules are actually rules that we are going to use for accessing this specific products API so we could add any kind of rule for a listing or viewing a single item creating item actually creating a product updating deleting so this Photograph operations here and we can add custom rules for that so because this is just for admins right now I'm going to add something here to have it for registered users so enable custom rule and outpace this that means if you requested user request is coming from a user that has an ID that is not empty that means that their user is registered so I'm gonna add that to to all of these and as we are talking about the products let's say that this is this is some kind of uh back office application for our products management uh we're gonna just uh show this as we're gonna set this as for authorized users let them do or do anything they want with the products so save changes and that's it for now here uh after that let's say that we have that we did some setup we can click here on this button and do an API preview here so viewing means that we can use in a JavaScript and node.js or anywhere in JavaScript and pocket base here and also we can use just we don't have to do that we can use API here first API that is interesting for us right now so for listing for getting a list of uh list of products let's say here we're going to use this get method here and they use this API as we're running on a local host it is just going to be on our Port that we have here in the terminal we said okay it is API 1890 and slash API and we can attach this uh this uh URL here so I'm gonna test something because I already did some testings on it I'm just gonna show you I'm gonna show you here uh this uh rest client as I'm using the standard client in vs code instead of uh Postman uh I'm gonna show you the testing for this so uh first of all I'm going to authorized with user actually I'm gonna log in to this application here and in our in our application here we can see users and we can go here API preview and we can use a outfit password and it also have the uh say it also allows us to use oauth uh for logging into another play into other play the sorry into the application and we are going to use uh this API to log in with our identity and password it is a username it's called an identity here so uh using this uh using this endpoint I'm going back to vs code and sending identity Adnan and my password Here clicking here and okay we have our status 200 and we see the details for this user so uh we see the role that we added and is actually a ID of the role uh of our collection and it is when it's updated the username is is it verified or anything we have in our collection and also we see a jvt token here that we are going to use for uh sending requests to our to our API so right now we're going to get all collections here from the uh from our collections of products so as you can see here on everything we have this API preview that we can click and see the apis for our collections that is really interesting as we don't need any kind of uh any kind of documentation as it is already going to be generated and with our parameters uh for that specific endpoint for example with viewing or creating products so we see the dummy data here for our products so uh okay and we're going to list all products so I'm going to hear API collection products and Records we see query parameters that we can use for sorting getting per page or doing anything with the products and now uh if I go to the visual studio code here uh I can use that get request here and send it but I have to add authorization here so the first thing is to play at the paste this jvt that I get here after logging in and another thing that I have to show you here is that when uh using the authorization here as for you in creating it doesn't matter it depends on the on the products we have to use we have to use in headers sorry okay uh okay in headers we have to set authorization to token so this is just a thing that we have to do and get others authorization authorization here and we have to set it okay okay and authorization is beer token and that's it we can hit send and as we don't have any items here in our application we cannot see anything but we can create an item so to do create here we can post that this uh the API here and we can use this dummy data here so I'll just copy this data and I'm gonna I'm going sorry to visual studio code and using this API the okay it's not okay here and in the body I'm just going to use this okay and here I'm gonna paste button in a Json file Json object actually and I'm pasting this uh this Json here so uh product is going to be let's say ice cream ice cream and some ice cream lots of chocolate and the price is going to be one point 89 and is available in our store and we can just uh send that request and also I have to just add the new uh I have to add a new token from here because I did this testing before sorry copy oh that's fine okay and hit send and we can see the response it is status 200. and now we can see it is the available collection ID Products and we can see it when it's created and everything regarding that product now we can go to no go back to this get request from this API hit send and now we can see items here and in the that items are a we can see our product here with the products with everything so this is when it comes to creating and getting the data and now we can also update the data so to update the data or I'll just use ID of this product here and let's say that we want to just update we just want to update the a price here so I'm gonna paste this ID here let's get it okay patch and into the query and I'm just going to change the price and add let's say it's not now it's maybe an action and we have a for 130. one for 130 and hit send and it's not okay because uh I haven't pasted a new jvt for this patch here okay and now it's send okay also having a problem with this assume with this talking here UPS patch oh that's not going to be to be sorry one one second here for some reason it's not copy it's a copy here I don't know what's going on but I can anytime go here and to show you this we can refresh our products we see our products here also in the that UI let's see uh back office or whatever you want admin panel for the API and we can just copy it here and also we can go back here and uh here just paste it as this and into the body we can see oops into the body here I'm sorry for this but into the body here what we said we want to change price and we just send it send the patch request here with providing ID of the product and we can see that the price has changed so we can also add some other price here hit send and we get it we don't have to send just like all the data or anything we're just sending the change data to it and it is updating automatically so uh this is it when it comes to patching and at least we have to delete some of this data and we can you do that by just pasting uh pasting here this uh ID and also I just have to add this here and hit send and it is actually not being okay the first I deleted at first so after getting the data we don't see anything after creating a data we'll create another one here sorry because I pasted it wrongly and I was gonna write down but okay we get it we get it here we can add ice cream too send it okay and now we can get we should have two ice creams here in the products and it is it and uh going back to this uh here application we can see we can see these products here so uh this is it when it comes uh to this uh this project based application here actually rest API that is really useful in in any cases or in just a testing purposes when you need an API and when you don't have to have time to create anything for yourself or if you need an API for small or let's say mid-size project you can use this one here without any kind of problems and you can do whatever you want so this is when it comes to it and thank you for watching and see you in the next one bye foreign
Info
Channel: Adnan Halilovic
Views: 4,766
Rating: undefined out of 5
Keywords: Backend development, REST API, Go Lang, Single-file solution, No-code, User authentication, Data storage, Server-side processing, Automatic database migrations, Logging, Error handling, Scalability, Extensibility, Framework integration, Developer tools, Web development, Adnan Halilovic, project-based learning
Id: 96iC5ofPXok
Channel Id: undefined
Length: 21min 29sec (1289 seconds)
Published: Sun Mar 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.