How can I generate my ids automatically with json-server? Does it no longer generate?

Discussão em 'Angular' iniciado por vinudev, Dezembro 7, 2024.

  1. vinudev

    vinudev Guest

    I'm using json-server as a fake api, and when making the POST request, my ids are not being generated automatically, note that they are already as a String, which is as recommended in the documentation.

    My class user

    export class User {
    public id: String = ''
    public name: String = ''
    public phone: String = ''
    public email: String = ''
    public cpf: String = ''
    public password: String = ''
    }


    from 10 to 13 I manually put the data in my db.json, after that we can notice that the id is not coming automatically

    {
    "id": "10",
    "firstName": "Bruno",
    "email": "brunohauck@gmail.com",
    "phone": "323",
    "cpf": "05126769685",
    "password": "fdsfds"
    },
    {
    "id": "11",
    "firstName": "Bruno",
    "email": "brunohauck@gmail.com",
    "phone": "323",
    "cpf": "05126769685",
    "password": "fdsfds"
    },
    {
    "id": "12",
    "firstName": "Bruno",
    "email": "brunohauck@gmail.com",
    "phone": "323",
    "cpf": "05126769685",
    "password": "fdsfds"
    },
    {
    "id": "13",
    "firstName": "Bruno",
    "email": "brunohauck@gmail.com",
    "phone": "323",
    "cpf": "05126769685",
    "password": "fdsfds"
    },
    {
    "id": "",
    "name": "teste",
    "phone": "1111111111",
    "email": "teste@gmail.com",
    "cpf": "18361591885",
    "password": "111"
    }
    ]


    on the npm website it says id is always a string and will be generated for you if missing

    Continue reading...

Compartilhe esta Página