Search code examples
loopbackjs

LoopBackJs REST API Create response not returning full model, only form data


when I POST to api/testmodel using an object with only the required fields, the object is being created correctly in the DB. However, I only get the object I sent in the request body. I'm trying to get the full object with null fields in the response.

Thanks for the help!

{
  "name": "test",
  "plural": "test",
  "base": "PersistedModel",
  "idInjection": true,
  "replaceOnPUT": false,
  "properties": {
    "city": {
      "type": "string",
      "length": 100
    },
    "name": {
      "type": "string",
      "required": true,
      "length": 100
    },
    "id": {
      "type": "string",
      "id": true,
      "required": true,
    },
    "officePhone": {
      "type": "string",
      "length": 100
    },
    "status": {
      "type": "string",
      "required": false,
      "length": 200
    },
    "street": {
      "type": "string",
      "length": 100
    }
  },
 "methods": {}`

Solution

  • Then you need to create default values for your model, for example city:

    "properties": {
        "city": {
          "type": "string",
          "length": 100,
          "default": ""
    
        },
    ...