Write REST API with Composite Entities in Express and Test using Postman - Lab Task 7




This is simple task. You have already looked at how to develop a REST API in lecture. We used 'product' entity as an example. In this task you are supposed to extend the lecture code by adding following stuff into API or endpoint:
  1. Create API for an object that has multiple attributes e.g. use student with id, name, gender, email, address, phone_numbers. Create multiple endpoints for different operations e.g. CRUD (Create, Retrieve, Update and Delete) and list multiple records.
  2. Add 'address' as field in the 'student' object. The 'address' shall be an object in itself with street_address, city and country as fields. It would make the 'student' object composite ... means, an object that has-a object.
  3. The 'phone_numbers' field should be an array of string i.e. you shall allow user to manage multiple numbers.
  4. It would help you to undertand how we can create and consume JSON for composite objects. In real applications, most of objects are composite in nature.
You can add some records in an array i.e. hard code in your code to start with, and add new records in same array sent on POST endpoint. In same way, edit, view and update operations shall be performed. You are not required to save or fetch these records in MongoDB.

Comments