Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
I don't know how to decide path of API on REST API in updating user information situation

PATCH /api/users/:id/email => user update email
PATCH /api/users/:id/nickname => user update nickname

As above, I designed path of API based on Rest API.
but, I have a question
I am using jwt
jwt_token has id information of user
i think, better way is to use id of user in jwt_token instead of adding id of user to parameter.
but, I have a another question

PATCH /api/email => user update email
PATCH /api/nickname => user update nickname

if i use id of user in jwt_token, API path will change like a example above.
I think, it`s strange.
because, According to Rest API, use collection.(ex. users, books and so on..)
What is the right thing to do?
thank you for reading

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

"REST" is the architectural style on which the HTTP protocol was built. Every web page was intended to be "RESTful" and REST itself says nothing about what the API should look like. The query is obviously about modern APIs. A modern API MUST adhere to the RFCs and at the same time SHOULD adhere to common conventions. Common conventions make the REST API understandable to consumers. Further, I am answering with respect to modern APIs.


If you want to do partial update of resource, you should use PATCH method. There are two ways (RFCs) which you can use: RFC 6902 aka JSON Patch and RFC 7396 aka Merge Match. URL should target the updated resource (USER):

PATCH  /users/:id

BUT: You wrote that you want to update only authenticated user. In this case is common to use "special" URL:

PATCH /me/profile

You should send JSON body based on preferred RFC. In case if RFC 7396:

{
   "email": "new@email.value",
   "nickname": "newNickname"
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda