Working with Vue 3 and Go (Golang)
- Descrição
- Currículo
- FAQ
- Revisões
Vue.js is, as they say on their website, an “approachable, performant and versatile framework for building web user interfaces.” That sentence really does not give Vue its full due. It is arguably the best solution currently available for building highly interactive, easy to maintain, and feature-rich web applications currently available. Many developers find it easier to learn than React or Angular, and once you learn the basics, it is easy to move on to building more complex applications.
Go, commonly referred to as Golang, is an easy to learn, type safe, compiled programming language that has quickly become a favourite among people writing API back ends, network software, and similar products. The ease with which Go works with JSON, for example, makes it an ideal solution to develop a back end for a Single Page Application written in something like Vue.
This course will cover all of the things you need to know to start writing feature-rich, highly interactive applications using Vue.js version 3 for the front end, and Go for the back end API.
We will cover:
-
Working with Vue 3 using a CDN
-
Working with Vue 3 using the vue-cli, node.js and npm
-
Learn both the Options API and the Composition API for Vue 3
-
How to work with props
-
How to build reusable Vue components
-
How to build and use a data store with Vue 3
-
Creating, validating, and posting forms using fetch and JSON
-
Emitting and processing events in Vue
-
Conditional rendering in Vue
-
Animations and transitions in Vue
-
Working with the Vue Router
-
Protecting routes in Vue (requiring user authentication)
-
Caching components using Vue’s KeepAlive functionality
-
Implementing a REST API using Go
-
Routing with Go
-
Connecting to a Postgresql database with Go
-
Reading and writing JSON with Go
-
Complete user authentication with Go using stateful tokens
-
Testing our Go back end with unit and integration tests
-
And much more.
Vue is one of the most popular front end JavaScript frameworks out there, and Go is quickly becoming the must-know language for developers, so learning them is definitely a benefit for any developer.
-
1IntroductionVídeo Aula
An overview of what we will be covering in this course.
-
2About meVídeo Aula
Just a bit of information about me and my background.
-
3Options API vs. Composition APIVídeo Aula
With the introduction of Vue.js version 3, we now have to application programming interfaces (APIs): the Options API, and the Composition API. We'll be covering both in this course.
-
4Installing GoVídeo Aula
Naturally, we'll need Go installed.
-
5Installing Visual Studio CodeVídeo Aula
If you don't have an IDE already, VS Code will do the job. Install it if you need to.
-
6Installing the Vetur VS Code extensionVídeo Aula
-
7Installing makeVídeo Aula
We won't be using make for awhile, but it's incredibly useful, so let's install it now.
-
8How to ask for helpVídeo Aula
When you need to ask for help, make it easy for me to give that help to you. Here's how.
-
9What we'll cover in this sectionVídeo Aula
-
10Using Vue with a CDN ( we'll use npm later)Vídeo Aula
Let's build the standard "Hello, world!" application. It's tradition, after all.
-
11The structure of a Vue appVídeo Aula
Let's have a quick look at how Vue works on a web page.
-
12Adding a simple form element and binding dataVídeo Aula
With vue, it's easy to bind a form element to another part of the web page. Let's give that a try.
-
13Adding a counterVídeo Aula
Let's add some additional interactivity to our application by listening for click events on a couple of buttons, and doing something when they are clicked.
-
14Vue Components - Getting StartedVídeo Aula
Components are one of the most valuable and powerful parts of Vue. Let's get started with components.
-
15Creating a reusable form input componentVídeo Aula
Let's create a re-usable Vue component that can be used to create any type of text input for an HTML form.
-
16Trying out our TextInput componentVídeo Aula
Let's try out our Vue component by building a simple user registration form.
-
17The Vue lifecycle and client side validationVídeo Aula
Vue applications have a certain lifecycle. It's important to know about it, and how to use it. Let's take advantage of Vue's lifecycle hooks and add some client-side JavaScript validation to our form.
-
18Nesting components within componentsVídeo Aula
Having a single component is fine, but it's incredibly useful to nest one or more Vue components within another Vue component. Let's try that by creating a (ficticious) user registration form.
-
19Adding a select form componentVídeo Aula
Let's build a select component, and add it to our registration form.
-
20Adding a checkbox form componentVídeo Aula
Let's add one more component - a checkbox.
-
21Conditional RenderingVídeo Aula
It's common to change what is displayed on a given web page depending on some condition. Vue makes it easy to do that with conditional rendering. Let's try it out.
-
22Fetching remote dataVídeo Aula
One of the things we do a lot in web applications is to fetch data from a remote service. Let's get started doing that in our Vue application.
-
23Using the data we fetch in our Vue applicationVídeo Aula
Now that we've pulled down some JSON from a remote source, let's work with it and display a list of books in our Vue application.
-
24Adding some interactivity to our list of booksVídeo Aula
Let's get started adding some interactivity to our list of books.
-
25Removing a book from the listVídeo Aula
Let's add an event listener to our list of books which allows us to remove a book from the list when the trash icon is clicked.
-
26Installing Node.jsVídeo Aula
In order to work with Vue 3 in this section of the course, we need Node and npm installed. Let's take care of that now.
-
27Installing vue-cliVídeo Aula
We also need vue-cli installed, so let's take care of that.
-
28Building and running a simple Vue application with vue-cliVídeo Aula
-
29The structure of a vue-cli applicationVídeo Aula
-
30Getting started with our appVídeo Aula
Let's remove most of the things that were auto-generated in our Vue app when we ran vue create vue-app, and get started from scratch.
-
31Registering header, body, and footer componentsVídeo Aula
Let's set up three simple Vue components for our application, register them, and add them to the main Vue component.
-
32Adding navigation to our header componentVídeo Aula
Let's add some more useful code to our header component.
-
33Adding content to our body componentVídeo Aula
Let's add some basic content to our Body Vue component.
-
34Adding content to our footer componentVídeo Aula
Let's add some content and styling to our Footer component.
-
35Installing the Vue RouterVídeo Aula
In order to make navigation actually work in our application, it is necessary to use some sort of router. Let's use the official Vue Router, which works really well.
-
36Getting started with the Vue RouterVídeo Aula
Let's set up some simple routes.
-
37Adding our routes in App.vue and main.jsVídeo Aula
Let's update main.js to tell our application that we are using a router, and then update App.vue to display the appropriate component.
-
38Creating a second component and updating our navigation linksVídeo Aula
Let's add a dummy Login Vue component, and update our Header component to use the router-link tag from the Vue Router.
-
39Adding and using our form Vue Components from the previous sectionVídeo Aula
Let's use the form Vue components we built in an earlier section and put together a Login component with the appropriate form.
-
40Creating and implementing a re-usable Form tag componentVídeo Aula
Let's make creating a <form> tag simpler by creating a new Vue component.
-
41Improving our Login form by binding data and listening for an eventVídeo Aula
Let's improve our login form by binding the form fields to the data associated with our component.
-
42Improving our FormTag and simplifying client side validationVídeo Aula
Let's update our FormTag and Login Vue components, and get them to the point where are ready to call the back end REST api. We won't be able to make that call until we actually write the api, but we'll get started on that in the next section.
-
43How Go works with JSON filesVídeo Aula
Let's have a quick look at the way Go works with JSON files.
-
44Setting up our projectVídeo Aula
Let's get started writing the Go code for our REST api.
-
45Improving routesVídeo Aula
Let's simplify things by installing a third part routing package, and moving our handlers into their own file, with one function per handler.
-
46Connecting from Vue to Go - the first tryVídeo Aula
Let's try connecting our front end Vue application to our back end API server.
-
47Implementing CORS in our routes.go fileVídeo Aula
Let's modify our routes.go file in the Go back end API to take care of CORS restrictions.
-
48Connecting from Vue to Go - the second tryVídeo Aula
Let's try connecting from our Vue front end to our Go back end API one more time, just to make sure CORS is set up properly in our routes file.
-
49ReadJSON and WriteJSON helper functionsVídeo Aula
Let's write two helper functions that make it easier to read & write JSON in our back end API.
-
50Simplifying our handlers to use the new helper functionsVídeo Aula
Let's update our Login handler to use our helper functions for reading and writing JSON.
-
51Adding a helper function to generate error messagesVídeo Aula
Let's write one more helper function that makes writing error responses back to the end user as JSON a simple one liner.
-
52Setting up a database with DockerVídeo Aula
-
53Choosing a Postgres clientVídeo Aula
If you don't already have a Postgres client, Beekeeper Studio will do the trick.
-
54Trying out Beekeeper and setting up a users tableVídeo Aula
Let's connect to our database with a Postgres client, and set up a simple users table.
-
55Creating a database driver packageVídeo Aula
Let's create a driver package that we'll use to connect our back end API to a Postgres database.
-
56Connecting to the database using our driver packageVídeo Aula
Let's clean up our driver package a bit, and then try connecting our API to the Postgres database.
-
57Using a Makefile to simplify our livesVídeo Aula
Let's get our hard coded database connection information out of our source code, and move them into an environment variable. We'll do this using a Makefile, which makes our lives much easier.
-
58Setting up a User modelVídeo Aula
We need some means of representing what is stored in the users table in Postgres in Go; let's set up a model to take care of that.
-
59Setting up the tokens tableVídeo Aula
Let's go back to Beekeeper Studio and set up a tokens table in our Postgresql database.
-
60Setting up a Token modelVídeo Aula
Let's set up a Token model in our data package, which will map what is in Postgres with our Go code.
-
61How we will write database functions for authenticationVídeo Aula
Let's simplify the way that we share database information to the various parts of our application, and set up a single function that connects to the database and gets a slice of all users stored in the users table.
-
62Manually adding a user to the databaseVídeo Aula
Let's add one row to the users table in the Postgres database so that we can try out our GetAll() function.
-
63Creating a test route and handler to try things outVídeo Aula
Let's make sure everything works by creating a test route that calls the GetAll function on our User type, and write some JSON to the browser window.
-
64Writing methods to get a user by email or idVídeo Aula
We'll need a few methods on the User type to get users, so let's write a couple: one to get a user by ID, and another to get a user by email address.
-
65Writing methods to update and delete usersVídeo Aula
Let's write the methods necessary to update a user, and to delete an existing user.
-
66Writing the Insert method for the User typeVídeo Aula
We're going to need to be able to insert users into the database, so let's write the Go code to insert a user into the Postgres database.
-
67Writing the Password reset and PasswordMatches functions for the User typeVídeo Aula
We are also going to need to be able to reset user passwords, and to validate a user supplied password to make sure it matches the hash that we have in the database. Let's take care of that.
-
68Getting started with methods for the Token typeVídeo Aula
Let's get started writing the necessary functions for the Token type.
-
69Generating and authenticating a tokenVídeo Aula
Let's write two functions on the Token type: one to generate a token, and another to authenticate a token and make sure that it's valid.
-
70Inserting and deleting tokensVídeo Aula
We're going to have to be able to insert and delete tokens, so let's take care of that.
-
71Adding a ValidToken method to the Token typeVídeo Aula
One useful function we can attach to the Token type is a means of ensuring that a given token is valid. In order to be considered valid, a token must exist, must be associated with a user that exists in the database, and it must not have expired. Let's create that function now.
-
72Trying out the database functions: adding a userVídeo Aula
Let's get started trying out the functions that interact with Postgres.
-
73Trying out generating a tokenVídeo Aula
Let's try out our GenerateToken function and make sure it works.
-
74Trying out the Token type's Insert functionVídeo Aula
Let's see if we got the function that inserts a token into the database right.
-
75Trying out the ValidToken functionVídeo Aula
Let's make sure that the ValidToken function works as expected by creating a test route and handler.
-
76Adding a unique constraint to the users tableVídeo Aula
Let's add a constraint to the users table which will only allow unique email addresses.
-
77Checking for database errors in errorJSONVídeo Aula
-
78Improving our jsonResponse type with an envelopeVídeo Aula
Let's make the JSON that we send back a bit more readable by implementing and using an envelope type.
-
79Updating our Login handlerVídeo Aula
In order to connect from our Vue front end to our Go back end and actually authenticate a user, we need to finish up our Login handler. Let's do that now.
-
80Updating the Vue front end to connect to /users/auth and get a tokenVídeo Aula
We already call the back end from our Vue application, but now we need to make some changes to our front end so that we actually pass the necessary data. Let's get started.
-
81Trying out authenticationVídeo Aula
Let's try authenticating and see if we get an error when we should, and that we get a token when we authenticate successfully.
-
82Sharing data between components using a simple storeVídeo Aula
-
83Improving the login processVídeo Aula
Right now, our login process is not very intuitive, since we don't give any kind of feedback to the user when they log in. Let's improve that.
-
84Logging outVídeo Aula
Let's get started making the logout process functional.
-
85Deleting a user's token on the back end on logoutVídeo Aula
In order to log a user out completely, we need to delete the token saved in the database. Let's take care of that.
-
86Making the request to delete a token from the front endVídeo Aula
Let's finish up the logout process by updating our Vue Header component to make a fetch request to the back end API in order to delete the user's token from the database.
-
87Saving the token as a cookieVídeo Aula
It's useful to save information like our token in a secure cookie so that users don't have to log in every time they visit the site. Let's take care of that now.
-
88Finishing up the improved login processVídeo Aula
Let's make some final changes to both the front and back end in order to compete our improved login process.
-
89An aside: speeding things up when writing JSON in productionVídeo Aula
While we're in development, it's useful to have nicely formatted JSON, but in production, that's a waste of resources. Let's make things more efficient by updating our Makefile to set an environment variable, and then use that in the API back end.
