{"id":27533,"date":"2018-02-16T10:00:17","date_gmt":"2018-02-16T15:00:17","guid":{"rendered":"https:\/\/simpleprogrammer.com\/?p=27533"},"modified":"2018-02-15T19:47:55","modified_gmt":"2018-02-16T00:47:55","slug":"building-highly-scalable-apis","status":"publish","type":"post","link":"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/","title":{"rendered":"Building Highly Scalable APIs with HapiJs and MongoDB"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-27553 alignright\" src=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/Building-Highly-Scalable-APIs-with-HapiJs-and-MongoDB-square.png\" alt=\"\" width=\"281\" height=\"281\" \/>Hapi.js (also known as hapi) is an open-source framework for web applications. The <a href=\"http:\/\/www.amazon.com\/exec\/obidos\/ASIN\/1633430219\/makithecompsi-20\">most common use of<\/a> hapi is to build web services such as JSON API. You can build application programming interface (API) servers, websites, and HTTP proxy applications with hapi.js.<\/p>\n<p>Hapi simplified the way in which developers write <a href=\"https:\/\/simpleprogrammer.com\/use-default-parameters-enumerations-make-apis-easier-use\/\">highly scalable APIs<\/a>. It is powerful and feature-rich framework with solid architecture. If you are new to hapi.js, I suggest you read my previous<a href=\"https:\/\/simpleprogrammer.com\/introduction-hapijs\/\"> introduction<\/a> article.<\/p>\n<h2>What Is a REST API?<\/h2>\n<p>A REST(Representational State Transfer) is an application program interface(<a href=\"https:\/\/en.wikipedia.org\/wiki\/Application_programming_interface\">API<\/a>) that uses <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hypertext_Transfer_Protocol\">HTTP<\/a> requests to GET, PUT, POST and DELETE data.<\/p>\n<p>A RESTful API\u2014also referred to as a RESTful web service\u2014is based on representational state transfer (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Representational_state_transfer\">REST<\/a>) technology, an architectural style and approach to communications often used in <a href=\"https:\/\/en.wikipedia.org\/wiki\/Web_service\">web services<\/a> development.<\/p>\n<p>Hapi provides some powerful features for building REST API. Some examples are Routing, Plugins, Logging, HTTP interface, Error Handling, etc.<\/p>\n<p>You do not need to work with the raw Node.js HTTP library. Hapi encapsulates the request and response object of HTTP request. Hapi allows you to build REST API faster. Let me show you how you can create APIS in hapi.js and mongoose<\/p>\n<h2>Installing Hapi.js<\/h2>\n<p>First of all, I am going to show you how to install hapi.js. Open your terminal and run the below commands. <strong>Npm init<\/strong> will create a new <strong>package.json<\/strong> file in the root directory of your application. You can install hapi on your local machine by using the npm install command. Npm(Node Package Manager) will grab the hapi package from the repository and save it to your local <strong>node_modules<\/strong> folder.<\/p>\n<p>npm init &#8212; yes<br \/>\nnpm install &#8212;\u00a0<em>save hapi<\/em><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<h3>API Endpoints Overview<\/h3>\n<p>I will show you how to build pure <strong>CRUD<\/strong> (Create, Read, Update, Delete) API endpoints with hapi.js. I have used some HTTP verbs such as <strong>POST<\/strong>, <strong>GET<\/strong>, <strong>PUT<\/strong>, and, <strong>DELETE<\/strong>.<\/p>\n<ul>\n<li><strong>POST<\/strong> \u00a0is used to create new records in the database<\/li>\n<li><strong>GET<\/strong> request is used to fetch records from the endpoints<\/li>\n<li><strong>PUT<\/strong> is used to update the record<\/li>\n<li><strong>DELETE<\/strong> is used to delete the record with MongoDB<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27534 aligncenter\" src=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/table.png\" alt=\"scalable apis\" width=\"703\" height=\"245\" \/><\/p>\n<h3>Creating a New Server<\/h3>\n<p>First of all, we need to create a new local server in hapi.js. Hapi allows you to create a new instance of the server from the <strong>hapi.Server()<\/strong> method. You can configure hapi server on a local machine by providing the host and port configuration. You must start the server by using the <strong>server.start<\/strong> method. If something goes wrong while starting the server it will throw this error:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/HaiderMalik12\/2953d5a8f49e775ca1642e62f23b7220.js\"><\/script><\/p>\n<h3>Run the Hapi Application<\/h3>\n<p>You can run hapi application on your local machine by executing this command:<\/p>\n<p>node server.js<\/p>\n<p>If the server started successfully, then you will see this message on your terminal or command prompt: <strong>Server Running at PORT 3000<\/strong><\/p>\n<h2>Connecting Hapi App to MongoDB<\/h2>\n<p>I am going to use MongoDB database to store my company\u2019s record. <a href=\"https:\/\/www.mongodb.com\/\">MongoDB <\/a>is a free and open source cross-platform document-oriented database program. Npm provides an excellent mongoose plugin to interact with MongoDB. <a href=\"http:\/\/mongoosejs.com\/\">Mongoose<\/a> (Object Document Mapper) is wrapper around the MongoDB.I will use <strong>Mongoose ODM<\/strong> to connect hapi application to MongoDB.You have to install mongoose package from the npm (Node Package Manager) repository.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/HaiderMalik12\/dd7e2d089455bdb1591a7d1d11f609c3.js\"><\/script><\/p>\n<h3>Running the MongoDB<\/h3>\n<p>Open your terminal and execute the mongod command, which will start the MongoDB server on your machine:<\/p>\n<p>mongod<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27535\" src=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/running-mongodb.png\" alt=\"highly scalable apis\" width=\"1335\" height=\"628\" \/><\/p>\n<h3>Creating a New database<\/h3>\n<p>I will save all of my company\u2019s data in the <strong>hapi_db <\/strong>database, but we have not created a database yet. To get started, open another tab in your terminal and execute this command:<\/p>\n<p>mongo .<\/p>\n<p>It will start the mongo shell on your machine, which allows you to run the MongoDB statements.<\/p>\n<p>Now you need to create the new database by running this command:<\/p>\n<p>use hapi_db<\/p>\n<p>It will create the <strong>hapi_db<\/strong> in your MongoDB database. You can see the output of the MongoDB server below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27537\" src=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/create-db.png\" alt=\"highly scalable apis\" width=\"1332\" height=\"279\" \/><\/p>\n<h3>Connecting to Mongoose<\/h3>\n<p>I am going to use mongoose to interact with MongoDB. Mongoose allows you to define your native MongoDB collection in Javascript object. You can also add validations to the model with the help of Mongoose.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/HaiderMalik12\/e277fb18ea352474fd06a427002d64e8.js\"><\/script> <span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<p><strong>Mongoose.connection<\/strong> is inherited from the nodejs <strong>EventEmitter<\/strong> class. I have registered a listener for the <strong>connected<\/strong> event. Nodejs will call the connected listener when the application is successfully connected to <strong>MongoDB. <\/strong><\/p>\n<p><strong>Server.connection<\/strong> is used to configure your host and port for hapi application. I have set the host to localhost and port to 3000. You can choose any port number, like 4000 or 8080.<\/p>\n<p><strong>Server.route <\/strong>is used to create a route in hapi.js. It will take a configuration object which must have <strong>path, method, and handler<\/strong> property. I have also registered an error listener for error events. Hapi will emit the error listener if it occurred while connecting to<\/p>\n<p><strong>MongoDB. reply<\/strong> method is used to send the response back to the user.<\/p>\n<h2>Creating a New Model<\/h2>\n<p>Everything in Mongoose starts with a Schema. Each schema maps to a MongoDB collection and defines the shape of the documents within that collection. The instance of the models represents the MongoDB document.<\/p>\n<p>You need to develop a new <strong>models<\/strong> directory in the project root directory. You also have to build a new model inside the model&#8217;s folder I am going to choose the <strong>company.model.js<\/strong> filename.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27538\" src=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/create-model.png\" alt=\"highly scalable apis\" width=\"342\" height=\"392\" \/><\/p>\n<p><script src=\"https:\/\/gist.github.com\/HaiderMalik12\/68ec4846e8ab5d62736411058db52e5d.js\"><\/script><\/p>\n<p>I have created a new <strong>CompanySchema<\/strong> to save the company records in MongoDB database. The schema represents the <strong>Collection<\/strong> in MongoDB. <strong>Mongoose.model<\/strong> represents the instance of the document in <strong>MongoDB<\/strong>. I have exported the instance of the model because I need to use this company model for other javascript (Controller) files.<\/p>\n<h2>Adding Record in MongoDB<\/h2>\n<p>Now I want to show you how to create a new company in MongoDB. I have created a new route with the <strong>\/api\/companies<\/strong> path. You have to send the HTTP <strong>POST<\/strong> request from the Postman. I will use Postman to send the request.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/HaiderMalik12\/a23c5ebd251a0d232c64e4f9d26404bb.js\"><\/script><\/p>\n<p>You can access request params from the <strong>req.payload<\/strong> object. I got the name and city of the payload object and also added required validation for the <strong>req.payload.name<\/strong> field. If the user does not provide the name while creating a new company, it will send the validation error in the response.<\/p>\n<p>I have invoked the create method from the mongoose <strong>Company<\/strong> model. You can also send the error to the response by using the <strong>reply<\/strong> method.<\/p>\n<p>If you send the request from postman to <strong>http:\/\/localhost:3000\/api\/companies<\/strong>, you will see the 200 status code in the response. The 200 status code means that the request has been executed successfully.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27539\" src=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/add-record.png\" alt=\"highly scalable apis\" width=\"1002\" height=\"733\" \/><\/p>\n<h2>Find All Records<\/h2>\n<p>We can also get all of the records from the company model. I am going to define the GET HTTP request endpoint to get all of the companies. You just need to send the HTTP GET request to this endpoint <strong>\/api\/companies.<\/strong><\/p>\n<p><script src=\"https:\/\/gist.github.com\/HaiderMalik12\/310c4154d3ae088bbbf10814b1a82f85.js\"><\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27540\" src=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/find-all-records.png\" alt=\"highly scalable apis\" width=\"1165\" height=\"615\" \/><\/p>\n<h3>Find a Single Record<\/h3>\n<p>The mongoose model class also provides the findById method for accessing a single record from the database. I am going to create a new endpoint to find a single company based on id. The path of this endpoint should be <strong>\/api\/companies\/{id}<\/strong>. I will send the company id dynamically from the postman.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/HaiderMalik12\/240c857efda65b9c22576ed6a249f3a2.js\"><\/script><\/p>\n<p>I have used the <strong>findById<\/strong> method to get a single company from MongoDB. If something goes wrong while fetching a record from the database, then you will receive <strong>404 (Bad Request)<\/strong> error. If there is no error in the response, then you will get the single Company in the reply.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27541 aligncenter\" src=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/findone-company.png\" alt=\"highly scalable apis\" width=\"1160\" height=\"507\" \/><\/p>\n<h2>Update Records<\/h2>\n<p>You can also update the company records in the database. I\u2019ll show you how to update a company by Id. You can use the<strong> findByIdAndUpdate<\/strong> method to update the record in <strong>MongoDB. <\/strong><\/p>\n<p>It will take four arguments: the first parameter is the <strong>id <\/strong>of the company which you want to upgrade, the second argument is the record to update object, and the third variable is the object with new property and the final argument you need to specify the <strong>callback function.<\/strong><\/p>\n<p><script src=\"https:\/\/gist.github.com\/HaiderMalik12\/38347192d13aac2e25c48bbc64db2125.js\"><\/script><\/p>\n<p>If the company does not update successfully, you will get a server error with the <strong>500 (Server Error) status code<\/strong>. If MongoDB updates the company successfully, you will receive the updated record of the company.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27542\" src=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/update-company.png\" alt=\"highly scalable apis\" width=\"1150\" height=\"671\" \/><\/p>\n<h2>Delete Record<\/h2>\n<p>If you want to remove any company, you will have to send the delete request to this URL <strong>http:\/\/localhost:3000\/api\/companies\/{id}.<\/strong> You have to provide this {id} dynamically from the Postman.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/HaiderMalik12\/a827bfddd10bd4358b9a3094909d6f62.js\"><\/script><\/p>\n<p>I am going to use the <strong>findByIdAndRemove <\/strong>method to destroy the company from the database. You just need to specify two arguments in this function. The first parameter should be the id of your company, and the second variable should be the callback function.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27543\" src=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/delete-company.png\" alt=\"highly scalable apis\" width=\"1164\" height=\"584\" \/><\/p>\n<h2>Refactoring the Application File Structure<\/h2>\n<p>I placed all my source code in a single file, which is the server.js file. If you are working on a large project, you must create a better file structure to organize your source code files.<\/p>\n<p>I am going to use some <strong>MVC(Model View Controller)<\/strong> design patterns for my file structure. I will place all my route actions or request handlers in my <strong>controller.js file <\/strong>and also have a separate file for defining routes. I am going to place all my mongoose models in the <strong>models<\/strong> directory.<\/p>\n<p>If you want to register a new endpoint in this application, you will need to add a new route in the <strong>routes.js <\/strong>file and add route action handler in the controller file. You can see the exact file structure in the below diagram.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27544\" src=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/restructure-app.png\" alt=\"highly scalable apis\" width=\"645\" height=\"447\" \/><\/p>\n<h2>Creating a New Company Controller<\/h2>\n<p>The <strong>Controller<\/strong> class is responsible for the following processing stages:<\/p>\n<ul>\n<li>Locating the appropriate action method to call and validating that it can be called.<\/li>\n<li>Getting the values to use as the action method&#8217;s arguments.<\/li>\n<li>Handling all errors that might occur during the execution of the action method.<\/li>\n<\/ul>\n<p>Now I will show you my company controller file. You can refactor your <strong>company.controller<\/strong> file by copying the code from this file.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/HaiderMalik12\/6935fcf7c6bfa344c733a0fd2aa6cf22.js\"><\/script><\/p>\n<h2>Creating New Company Routes<\/h2>\n<p>Each route has a request handler or action method. We will place the application logic in the controller file. I will define my company related endpoints in <strong>company.routes.js<\/strong>. I already mentioned that you should have a separate route file for each controller. I have also applied <strong>SRP (Single Responsibility Pattern)<\/strong>. Each file should have a single responsibility. Let\u2019s look at the code in the <strong>company.routes.js<\/strong> file.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/HaiderMalik12\/45d038656c3c8f4dbf77c1e3da7b4b27.js\"><\/script><\/p>\n<h3>Mastering Hapi.js to Build Scalable APIs<\/h3>\n<p>You have learned how to build CRUD (Create, Read, Update, DELETE) Restful API in hapi.js. Now you are able to integrate hapi to MongoDB.<\/p>\n<p>I have also showed you some of the best practices for maintaining folder structure in hapi.js. In the next article, I will show you how to add <em>validations in Hapi.js.<\/em> You can download the complete <a href=\"https:\/\/github.com\/HaiderMalik12\/hapi-casts\/tree\/master\/building-apis\">source code<\/a> for the building apis module.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hapi.js (also known as hapi) is an open-source framework for web applications. The most common use of hapi is to build web services such as JSON API. You can build application programming interface (API) servers, websites, and HTTP proxy applications with hapi.js. Hapi simplified the way in which developers write highly scalable APIs. It is&#8230;<\/p>\n","protected":false},"author":1101,"featured_media":27552,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[415,162229803,162229823,162229253],"tags":[],"class_list":["post-27533","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guest-post","category-programming","category-software","category-technical"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Building Highly Scalable APIs with HapiJs and MongoDB - Simple Programmer<\/title>\n<meta name=\"description\" content=\"Hapi simplified the way in which developers write highly scalable APIs. It is powerful and feature-rich framework with solid architecture.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Building Highly Scalable APIs with HapiJs and MongoDB - Simple Programmer\" \/>\n<meta property=\"og:description\" content=\"Hapi simplified the way in which developers write highly scalable APIs. It is powerful and feature-rich framework with solid architecture.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/\" \/>\n<meta property=\"og:site_name\" content=\"Simple Programmer\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-16T15:00:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/Building-Highly-Scalable-APIs-with-HapiJs-and-MongoDB.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/building-highly-scalable-apis\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/building-highly-scalable-apis\\\/\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"Building Highly Scalable APIs with HapiJs and MongoDB\",\"datePublished\":\"2018-02-16T15:00:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/building-highly-scalable-apis\\\/\"},\"wordCount\":1824,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/building-highly-scalable-apis\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/simpleprogrammer.com\\\/wp-content\\\/uploads\\\/2018\\\/02\\\/Building-Highly-Scalable-APIs-with-HapiJs-and-MongoDB.png\",\"articleSection\":[\"Guest Post\",\"Programming\",\"Software\",\"Technical\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/simpleprogrammer.com\\\/building-highly-scalable-apis\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/building-highly-scalable-apis\\\/\",\"url\":\"https:\\\/\\\/simpleprogrammer.com\\\/building-highly-scalable-apis\\\/\",\"name\":\"Building Highly Scalable APIs with HapiJs and MongoDB - Simple Programmer\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/building-highly-scalable-apis\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/building-highly-scalable-apis\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/simpleprogrammer.com\\\/wp-content\\\/uploads\\\/2018\\\/02\\\/Building-Highly-Scalable-APIs-with-HapiJs-and-MongoDB.png\",\"datePublished\":\"2018-02-16T15:00:17+00:00\",\"author\":{\"@id\":\"\"},\"description\":\"Hapi simplified the way in which developers write highly scalable APIs. It is powerful and feature-rich framework with solid architecture.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/building-highly-scalable-apis\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/simpleprogrammer.com\\\/building-highly-scalable-apis\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/building-highly-scalable-apis\\\/#primaryimage\",\"url\":\"https:\\\/\\\/simpleprogrammer.com\\\/wp-content\\\/uploads\\\/2018\\\/02\\\/Building-Highly-Scalable-APIs-with-HapiJs-and-MongoDB.png\",\"contentUrl\":\"https:\\\/\\\/simpleprogrammer.com\\\/wp-content\\\/uploads\\\/2018\\\/02\\\/Building-Highly-Scalable-APIs-with-HapiJs-and-MongoDB.png\",\"width\":1280,\"height\":720},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/building-highly-scalable-apis\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/simpleprogrammer.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Building Highly Scalable APIs with HapiJs and MongoDB\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/simpleprogrammer.com\\\/#website\",\"url\":\"https:\\\/\\\/simpleprogrammer.com\\\/\",\"name\":\"Simple Programmer\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/simpleprogrammer.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"\",\"url\":\"https:\\\/\\\/simpleprogrammer.com\\\/author\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Building Highly Scalable APIs with HapiJs and MongoDB - Simple Programmer","description":"Hapi simplified the way in which developers write highly scalable APIs. It is powerful and feature-rich framework with solid architecture.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/","og_locale":"en_US","og_type":"article","og_title":"Building Highly Scalable APIs with HapiJs and MongoDB - Simple Programmer","og_description":"Hapi simplified the way in which developers write highly scalable APIs. It is powerful and feature-rich framework with solid architecture.","og_url":"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/","og_site_name":"Simple Programmer","article_published_time":"2018-02-16T15:00:17+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/Building-Highly-Scalable-APIs-with-HapiJs-and-MongoDB.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Written by":"","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/#article","isPartOf":{"@id":"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/"},"author":{"name":"","@id":""},"headline":"Building Highly Scalable APIs with HapiJs and MongoDB","datePublished":"2018-02-16T15:00:17+00:00","mainEntityOfPage":{"@id":"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/"},"wordCount":1824,"commentCount":0,"image":{"@id":"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/#primaryimage"},"thumbnailUrl":"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/Building-Highly-Scalable-APIs-with-HapiJs-and-MongoDB.png","articleSection":["Guest Post","Programming","Software","Technical"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/","url":"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/","name":"Building Highly Scalable APIs with HapiJs and MongoDB - Simple Programmer","isPartOf":{"@id":"https:\/\/simpleprogrammer.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/#primaryimage"},"image":{"@id":"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/#primaryimage"},"thumbnailUrl":"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/Building-Highly-Scalable-APIs-with-HapiJs-and-MongoDB.png","datePublished":"2018-02-16T15:00:17+00:00","author":{"@id":""},"description":"Hapi simplified the way in which developers write highly scalable APIs. It is powerful and feature-rich framework with solid architecture.","breadcrumb":{"@id":"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/#primaryimage","url":"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/Building-Highly-Scalable-APIs-with-HapiJs-and-MongoDB.png","contentUrl":"https:\/\/simpleprogrammer.com\/wp-content\/uploads\/2018\/02\/Building-Highly-Scalable-APIs-with-HapiJs-and-MongoDB.png","width":1280,"height":720},{"@type":"BreadcrumbList","@id":"https:\/\/simpleprogrammer.com\/building-highly-scalable-apis\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/simpleprogrammer.com\/"},{"@type":"ListItem","position":2,"name":"Building Highly Scalable APIs with HapiJs and MongoDB"}]},{"@type":"WebSite","@id":"https:\/\/simpleprogrammer.com\/#website","url":"https:\/\/simpleprogrammer.com\/","name":"Simple Programmer","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/simpleprogrammer.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"","url":"https:\/\/simpleprogrammer.com\/author\/"}]}},"_links":{"self":[{"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/posts\/27533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/users\/1101"}],"replies":[{"embeddable":true,"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/comments?post=27533"}],"version-history":[{"count":0,"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/posts\/27533\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/media\/27552"}],"wp:attachment":[{"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/media?parent=27533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/categories?post=27533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/simpleprogrammer.com\/wp-json\/wp\/v2\/tags?post=27533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}