Back to Blog
Loopback api6/25/2023 ![]() ![]() The JSON file specifies all metadata about the entity: properties, relations, validations, roles and method names. The model generator will create two files which define the model in the application’s common/models: gift.json and gift.js. Gift will have name and description properties: Let's add some Gift properties now.Įnter an empty property name to indicate you are done defining properties. ? Custom plural form (used to build REST URL):įinally, we give the names of properties, their data types, and required/not-required flags. ? Expose Gift via the REST API? (Y/n) Yes ? Select model's base class: (Use arrow keys) ? Select the data-source to attach Gift to: (Use arrow keys) Press enter here to use the default, which is simply the plural of the model name (in our case, gifts). Next, LoopBack asks if it should expose the model through REST (yes), and the name of the REST service. The base class is an auto-generated model class, and we want to use PersistedModel in this case, as it already contains all the usual CRUD methods for us. Since we haven’t set up the data source yet, we can put db (memory). LoopBack will ask for the data source and base class. ? What's the name of your application? Givesomebody Then run LoopBack’s application generator: $ slc loopback Install the StrongLoop command line tools through npm: $ npm install -g strongloop The name of this groundbreaking application will be Givesomebody. Of course, we could build Donors and Receivers as separate roles on the same entity (User), but let’s try separating them so we can see how to build relations in LoopBack. A Receiver can see the list of gifts from all users, and can claim any that are unclaimed. A Donor can create a new gift and see the list of gifts. So, the users will be Donors and Receivers. Our application will manage people who would like to donate gifts, or things they just don’t need anymore, to somebody who might need them. npm comes with it, so you can install the necessary packages easily. You will of course need Node installed on your machine to follow along. We’ll use this since it makes it easier to see the results of our work, and so that our example can focus on building the API itself. LoopBack comes with a built-in client, API Explorer. Built on top of Express, it can take a data model definition and easily generate a fully functional end-to-end REST API that can be called by any client. ![]() LoopBack is a framework for creating APIs and connecting them with backend data sources. ![]() What is LoopBack and How Does It Work with Node? Let’s take a closer look at LoopBack and it’s capabilities by turning everything into practice and building an example application. StrongLoop is an important contributor to the latest Node version, not to mention the long-time maintainers of Express, one of the most popular Node frameworks in existence. But, there is a powerful contender gaining steam: LoopBack, an open source API framework built by San Mateo, Calif., company StrongLoop. While Ruby has Rails and Python has Django, the dominant application development framework for Node has yet to be established. On the development side, the Node package manager ( npm) continues to grow rapidly, recently surpassing 150,000 hosted modules. On Thanksgiving weekend in 2014, Walmart servers processed 1.5 billion requests, 70 percent of which were delivered through mobile and powered by Node.js. Walmart’s mobile site has become the biggest Node application, traffic wise. PayPal is actively rebuilding their front-end in Node. eBay has been running a production Node API service since 2011. It’s needless to mention the growing popularity of Node.js for application development.
0 Comments
Read More
Leave a Reply. |