Skip to content

EasyWeb Authentication & Restful API

Bao Trinh edited this page Nov 17, 2016 · 5 revisions

Apply Application Standards for EasyWeb systems

Authentication

  • External Authentication using Github, Gmail, Facebook,
  • private authentication using EasyWeb account
  • after authenticated, return access token, and redirect to corresponding url

Restful API Standard

EndPoint: api.easywebhub.com

Must have access token, after authorized at Authentication, to access

EasyWeb Users

  • GET: /users
  • GET: /users/userId
  • GET: /user/userId/websites (websites of a user)
  • PUT (PATCH): /user/userId/websites/webId (add a website managed by a user)

User websites

  • GET: /websites

    • get basic info of list websites
  • POST: /websites (create a new website with owner userId, defined in json body)

  • GET: /websites/webId

    • get fullInfo of a website
  • PUT: /websites/webId/userID (assign a user with permission for a web)

    • need to call PUT of user, /user/userId/websites/webId
  • DELETE: /websites/webId/userId (remove a user permission)

Shopping cart:

  • GET : /websites/webID/orders : get all orders of this website
  • POST: /websites/webID : (include web publicKey)
    • order info defined on json body

Comment System

  • GET: urls/urlId/comments (like, share, rating)

Marketplace

  • GET /markets : get list websites on marketplace
  • POST /markets

References

Restful API:

https://codeplanet.io/principles-good-restful-api-design/

  • GET (SELECT): Retrieve a specific Resource from the Server, or a listing of Resources.

  • POST (CREATE): Create a new Resource on the Server.

  • PUT (UPDATE): Update a Resource on the Server, providing the entire Resource.

  • PATCH (UPDATE): Update a Resource on the Server, providing only changed attributes.

  • DELETE (DELETE): Remove a Resource from the Server.

Filters

  • ?limit=10: Reduce the number of results returned to the Consumer (for Pagination)
  • ?offset=10: Send sets of information to the Consumer (for Pagination)
  • ?animal_type_id=1: Filter records which match the following condition (WHERE animal_type_id = 1)
  • ?sortby=name&order=asc: Sort the results based on the specified attribute (ORDER BY name ASC)

Status của API

It is very important that as a RESTful API, you make use of the proper HTTP Status Codes; they are a standard after all! Various network equipment is able to read these status codes, e.g. load balancers can be configured to avoid sending requests to a web server sending out lots of 50x errors

  • 200 OK – [GET]
    • The Consumer requested data from the Server, and the Server found it for them (Idempotent)
  • 201 CREATED – [POST/PUT/PATCH]
    • The Consumer gave the Server data, and the Server created a resource
  • 204 NO CONTENT – [DELETE]
    • The Consumer asked the Server to delete a Resource, and the Server deleted it
  • 400 INVALID REQUEST – [POST/PUT/PATCH]
    • The Consumer gave bad data to the Server, and the Server did nothing with it (Idempotent)
  • 404 NOT FOUND – [*]
    • The Consumer referenced an inexistant Resource or Collection, and the Server did nothing (Idempotent)
  • 500 INTERNAL SERVER ERROR – [*]
    • The Server encountered an error, and the Consumer has no knowledge if the request was successful

Clone this wiki locally