Giter Site home page Giter Site logo

useradmin's Introduction

Users API

Disclaimer

This is an API that was made as part of an interview process. The endpoints described in this API are:

/user/create

/user/login

/user/{uid}

The tests were made so that they guarantee the business rules and not the communication rules so if it's needed to change to a CLI API or any other communication type it may be done easily.

Create Endpoint

The create endpoint was made to receive a POST request with the body as the following JSON:

{
 "name": "João da Silva",
 "email": "[email protected]",
 "password": "hunter2",
 "phones": [
     {
         "number": "987654321",
         "ddd": "21"
     }
 ]
}

Afterwards, if the user doesn't exist yet it will return a status 201 with the user object json as bellow:

 {
     "uid": "c2cf4b90-46fb-4cae-8069-ea159879b7ed",
     "name": "João da Silva",
     "email": "[email protected]",
     "password": "wpFbpzehjKCaRlyBEBfRytVIJy0wb3f9K1Lh7ktJizI=",
     "salt": "624yiKthag+NwtiL1VG1/g==",
     "created": "2020-05-05T03:43:08.024",
     "modified": "2020-05-05T03:43:08.023",
     "lastLogin": "2020-05-05T03:43:08.024",
     "token": "49bdedd5-dec9-4ee5-af4c-09bcd223b71b",
     "phones": [
            {
                 "number": "987654321",
                 "ddd": "21"
            }
     ]
 }

Otherwise it will return an error msg with either a http code 400 if the request doesn't have all the required parameters or a 422 if the email is already associated to a user in the database.

Login

The Login endpoint accepts a json of the form:

{
    "email": "[email protected]",
    "password": "hunter2"
}

And returns a http status 200 and user object in the body as follows:

{
     "uid": "c2cf4b90-46fb-4cae-8069-ea159879b7ed",
     "name": "João da Silva",
     "email": "[email protected]",
     "password": "wpFbpzehjKCaRlyBEBfRytVIJy0wb3f9K1Lh7ktJizI=",
     "salt": "624yiKthag+NwtiL1VG1/g==",
     "created": "2020-05-05T03:43:08.024",
     "modified": "2020-05-05T03:43:08.023",
     "lastLogin": "2020-05-05T03:43:08.024",
     "token": "49bdedd5-dec9-4ee5-af4c-09bcd223b71b",
     "phones": [
            {
                 "number": "987654321",
                 "ddd": "21"
            }
     ]
 }

If the email or password aren't both correct the return will be a 401 http status and an error message.

Profile

For the Profile request, the UID must be suplied in the URL. Also, to access a given profile you must also send an Authorization header containing a "Bearer ". If the token an uid don't match a 401 http status will be returned otherwise it will return a User Object:

{
     "uid": "c2cf4b90-46fb-4cae-8069-ea159879b7ed",
     "name": "João da Silva",
     "email": "[email protected]",
     "password": "wpFbpzehjKCaRlyBEBfRytVIJy0wb3f9K1Lh7ktJizI=",
     "salt": "624yiKthag+NwtiL1VG1/g==",
     "created": "2020-05-05T03:43:08.024",
     "modified": "2020-05-05T03:43:08.023",
     "lastLogin": "2020-05-05T03:43:08.024",
     "token": "49bdedd5-dec9-4ee5-af4c-09bcd223b71b",
     "phones": [
            {
                 "number": "987654321",
                 "ddd": "21"
            }
     ]
 }

useradmin's People

Contributors

ariaqf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.