skip to Main Content

There is an endpoint called /data which contains some fields. How can I create a new field in this endpoint?
before:

{
  "data": {
    "name": "...",
    "surname": "..."
  }
}

after the api.post('/data', { email }) request, /data should look like this:

{
  "data": {
    "name": "...",
    "surname": "...",
    "email": "..."
  }
}

but currently, when I add a new field, the other ones are being deleted:

{
  "data": {
    "email": "..."
  }
}

2

Answers


  1. Because you are only passing email, as mentioned by you:

    api.post(‘/data’, { email })

    If you mean appending email in body of post request :

    let data ={name, surname} //suppose    
    api.post('/data', { ...data,email });
    
    Login or Signup to reply.
  2. If I understand correctly, you want that the /data endpoint remembers the previous REST calls, and simply adds/overwrites object key/values. Because REST is stateless you need a persistent storage to achieve that, such as MySQL, MongoDB, or Memcached.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search