Giter Club home page Giter Club logo

users-api-example's Introduction

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":"[email protected]","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":"[email protected]","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

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.