Skip to content

gsavio/users-api-example

Repository files navigation

Simple Users Administration API

A simple API REST for users administration

References

Installation

Run the composer to install laravel and dependencies

$ composer install

To generate your key

$ php artisan key:generate

And then run the migrations to create the database tables along with the seeds to populate the tables

$ php artisan migrate --seed

There is even a docker-compose file. You must have docker and docker-compose installed. And then run the command:

$ docker-compose up -d

If you want to use docker, configure the .env file according to docker-compose or copy the .env-docker.example file and rename to .env.

API usage

Show all users

Return a json list of all users registered

  • URL

    /users

  • Method

    GET

  • Header

    Content-Type: application/x-www-form-urlencoded

  • Data

    None

  • Success Response

    • Code: 200
      Content: [{"id":1,"name":"John Doe","age":61,"email":"johndoe@example.com","phone":"(99) 99999-9999","city":"City Name","state":"AA","created_at":"YYYY-MM-DD HH:MM:SS","updated_at":"YYYY-MM-DD HH:MM:SS"}]
  • Error Response

    • Code: 200
      Content: {"response":"No registered users"}

Show user

Return json about a single user

  • URL

    /users/{id}

  • Method

    GET

  • Header

    Content-Type: application/x-www-form-urlencoded

  • Data

    None

  • Success Response

    • Code: 200
      Content: [{"id":1,"name":"John Doe","age":61,"email":"johndoe@example.com","phone":"(99) 99999-9999","city":"Porto Guilherme","state":"CE","created_at":"2019-06-16 02:47:53","updated_at":"2019-06-16 02:47:53"}]
  • Error Response

    • Code: 404
      Content: {"error":"User not found"}

Create user

  • URL

    /users

  • Method

    POST

  • Header

    Content-Type: application/x-www-form-urlencoded

  • Data

    name string
    age int
    email string
    phone string
    city string
    state string

  • Success Response

    • Code: 201
      Content: {"response": "User {name} created"}
  • Error Response

    • Code: 400
      Content: {"error": ...}

Edit user

  • URL

    /users/{id}

  • Method

    PUT

  • Header

    Content-Type: application/x-www-form-urlencoded

  • Data

    name string
    age int
    email string
    phone string
    city string
    state string

  • Success Response

    • Code: 201
      Content: {"response": "User {name} updated"}
  • Error Response

    • Code: 400
      Content: {"error": ...}

Delete user

  • URL

    /users/{id}

  • Method

    DELETE

  • Header

    Content-Type: application/x-www-form-urlencoded

  • Data

    None

  • Success Response

    • Code: 201
      Content: {"response": "User deleted"}
  • Error Response

    • Code: 404
      Content: {"error": "User not found"}

Running tests

To run tests if you're using docker, you need to start the command line using docker-compose exec web followed by comando you need, eg.:

$ docker-compose exec web vendor/bin/phpunit

If you don't, to run the 2 tests written run this command:

$ vendor/bin/phpunit

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published