showing 17 lessons...
In this lesson we will look at the filters that can be used to retrieve and manipulate the data stored in LoopBack.
We will use Postman to interact with the
Using the URL parameters we will apply at the various filters LoopBack has to offer:
In this lesson we will look at how to deploy our LoopBack API project using now.
We will install the now client, create an account and deploy our app.
now secrets features we will store our database connection url which we get by creating a free MongoDB Atlas database.
In order to simplify following deployments we will add a
now key to our
package.json where we use the
env parameters to configure our deployments. We will add some npm scripts so we can deploy our app in the desired way using
npm run now.
In this lesson we will create a free account on monogdb.com. After the account has been created we will create a group in MongoDB Atlas and in that group we create a free cluster. In order to create the cluster we need to provide a username and password. We create our user called
admin and have the site generate our password for use. Once the cluster is created we look at where we can find the connection string.
In this lesson we will create a dynamic datasource in LoopBack. If the API is started with the environment variable
MONGODB_URL it will use this url and the
loopback-connector-mongodb package to store the data in MongoDB.
In the course we will use a local MongoDB instance. If you don't have MongoDB running locally you can always create a free MongoDB Atlas database.
In this lesson we look at extending the functionality of LoopBack models by defining a remote method.
A remote method is a method on a model exposed over a custom REST endpoint.
lb remote-method command we will create the remote method meta-data in
product.json. We will verify that this got created and that we see the new REST endpoint got added. Then we will create the actual method in
product.js and enhance it so that the API will return an error if we want to buy a negative amount of products.
In this lesson we will learn how to create a boot script.
We will use a boot script to create or update a predefined admin user, and give that user an Access Token. That way we don't have to log in to the API each time we want to use it as an authenticated user.
In this lesson we will learn how to protect our API using ACL’s.
ACL stands for Access Control List and it's function is to control permissions of resources in the API. It does this by keeping a mapping between an API resource and a principal. An API resource as an API endpoint like a remote method or a whole model. A principal in LoopBack are users or applications that can be grouped in a role.
In order to get the API production ready we will protect a selection of our REST endpoints with ACL’s. We will look at how we can obtain an access token and how we can use that in our requests.
Finally we will write some unit tests to make sure that the ACL does what we expect. We enhance our test setup by exporting
request with is provided by the supertest library.
In our tests we use
request to verify that our endpoints return the correct HTTP status code.
In this lesson we will learn how to add operation hooks to our models. In the Product model we will create a
before safe observer that will check if the category we want to add the product to exists.
In our Category model we will create a
before delete observer to prevent categories from being deleted when they have products.
We will create a unit test to verify that both of these operation hooks work as expected.
In this lesson we will learn how to add tests to the project to make sure our API behaves as we expect.
chai as devDependencies we will add
test:watch scripts to our
package.json. We will create a different datasource what we will use when running the tests by copying
datasources.test.json and prefixing our
test command with
We will verify that our tests run against an empty datasource. We’ll also add various tests to verify that our remote method and validation on the Product model behave as expected.
We can add validation rules to our models to make sure the data we store in our API is how we want it.
In this lesson we will add validation rules to the Product model.
We will make sure the product name has a minimal length using the
validatesLengthOf rule and that it is unique using the
For the price property we will add a custom validation to make sure that the value entered is not a negative integer. Additionally we will show how to do an async validation using
validateAsync . This can for instance be useful if you want the validation to depend on a value in the database or a remote system.
A relation in LoopBack is a way to associate the data from multiple models with each other. LoopBack supports various types of relations each with a different use case.
In this lesson we will create a second model called Category and create a relation between the Category and the Product models. To do this we will first add a property to the Product model called
categoryId. This will allow us to store for each Product the category it belongs to. We then move on to create the actual relationships.
Our first relationship defines that a
Category hasMany Products and the second one that a
Product belongsTo a Category.
After defining these relations we will use the API Explorer to see how we can interact with this related data.
In this lesson we will learn to create a development mode for our server. We do this by installing nodemon as a dev dependency and creating a script tag called 'dev'.
This script tag will execute the command
nodemon server/server.js --watch common --watch server.
We can execute this command by running
npm run dev.
When running in development mode the server will be automatically restarted when there are changes detected in the
GlimmerJS is a UI component library built by the Ember.js team. It is fast and lightweight and uses a combination of TypeScript and Handlebars to build the components.
In this lesson we will use the Ember CLI to initialize a new GlimmerJS project.
We will start by installing Ember CLI globally by running
npm install -g ember-cli/ember-cli.
Next we will use the
ember command to create our new project by running
ember new egghead-glimmer -b @glimmer/blueprint .
When our project is created we
cd into the project directory and start the development server. We will view the page in the browser and change the base template.
React Native requires a lot of initial set up to get an app going. In this lesson, we will use create-react-native-app to do this initial setup for us. We will install
create-react-native-app globally and create a new project.
After creating the project we will run the development server which will print a QR code on the terminal. We will install the app called
Expo Client on our mobile phone and use it to scan the QR code.
This will load our app on our mobile phone in development mode. When make adjustments to our project the changes will be reflected on our phone. If we use
console.log the messages will be printed in our terminal.
In this lesson you will learn how to persist the data from the memory connector. As the name suggests, the memory connector stores the data in memory. This means that if you restart the server, the data is gone. In development mode it can be useful to store this data in a file, so it gets persisted between server restarts, and it can be easily inspected.
In this lesson you will learn what a LoopBack model is, you will create a Product model using the LoopbBack CLI. The product model will be based off the built-in PersistedModel which gives it basic functionality like Create, Ready, Update, Delete and some more. Using the API Explorer you can interact with the new model, store, retrieve, edit and delete the product data.
LoopBack is a framework built on top of Express for creating APIs. It allows you to create end-to-end REST APIs that can access data from many data sources such as MondoDB, PostgreSQL, MySQL or other REST APIs.
In this lesson you will learn how to install loopback-cli and create a new LoopBack API project. After creating the basic LoopBack project through the CLI, running the server will give us access to the project and API Explorer urls. The user model will be available to us because user authentication was enabled.