įor more information about the architecture and typical usage of Loopback, see my Loopback talk. The relationship between each patient and a physician can then be handled fully inside Loopback by constructing what are called relations. Then, each model could be connected to backing storage via a connector.įurthermore, the connector does not have to be the same for each model: physicians could be stored on a MySQL database and patients stored on a MongoDB instance, for example. For instance, if one were building an API to represent a hospital, a “physician” model could be created that contains properties such as specialty, years practiced, and gender, and a separate “patient” model containing, for example, properties for a patient’s age, gender, address, and phone number. The idea behind this separation of concerns is that you can describe the shapes of – and relationships between – your data separately from describing how to retrieve or update that data. There are many connectors available, such as MongoDB, MySQL, and PostgreSQL, which are installed as NPM packages. In Loopback, a model represents the schema of one instance of a certain kind of data, and a connector enables any number of models to interact with backing storage. Incidentally, a configured instance of a connector is called a data source. Architecture of Loopbackīriefly, Loopback represents groups of data abstractly as models that interact with backing storage via connectors. Thus, as we will see, TypeScript can afford type safety in any Loopback project with minimal headache. As a first-order approximation, TypeScript is merely typed JavaScript, and TypeScript readily transpiles into JavaScript. While motivating TypeScript over JavaScript is beyond the scope of this post, there are many persuasive arguments for using types as a first line of defense against bugs. Background and Motivation TypeScriptīy default, Loopback projects are configured with JSON files and coded in JavaScript by default. In this article I will explain how to convert any Loopback 3 project to TypeScript and also how you can expand your API’s capabilities by creating your own connector. Although Loopback 3 does not use TypeScript, any Loopback 3 project can be converted to use TypeScript today. While Loopback 4 will use TypeScript by default, version 4 has not yet been released. Also, many developers would like to use TypeScript with Loopback. In cases like this, the best solution is often to write your own connector. While the CLI allows for easy configuration of Loopback’s JSON files via simple command-line operations, there are times when you need to write code to expand the functionality of your API, especially when the backing storage is not an off-the-shelf database but a custom enterprise API. In that talk I created a vanilla Loopback API using the Loopback CLI and connected the resulting API to the Angular Tour of Heroes demo application. Recently, I gave a talk about creating APIs with Loopback in the context of building Angular web apps. Loopback is a powerful Node.js API framework built on top of Express that comes with a lot of functionality in-the-box.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |