常忘 发布的文章

地址:https://mirrors.aliyun.com/composer/index.html

使用 Composer 镜像加速有两种选项:

  • 选项一:全局配置,这样所有项目都能惠及(推荐);
  • 选项二:单独项目配置;

选项一、全局配置(推荐)

$ composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

选项二、单独使用

如果仅限当前工程使用镜像,去掉 -g 即可,如下:

$ composer config repo.packagist composer https://mirrors.aliyun.com/composer/

取消镜像

composer config -g --unset repos.packagist
composer config --unset repos.packagist

Development Convention

Http Response

Success:

{
   "result":"success",
   "meta":"<Meta Object, like pagination options|Optional>",
   "message":"<success messages|Optional>",
   "data":"<Data Object or Data Arrary|Optional>"
}

failure

{
   "result":"failure",
   "message":"<failure messages|Optional>",
   "data":"<Data Object or Data Arrary|Optional>",
   "errors":"<Extended error message Array or Object |Optional>"
}

Usage

Create or update a resource success

  • status 200
{
  "result": "success",
  "data": {
    "object_id": "a3d182dc-04ba-4fba-96ff-d07580baff2b",
    "property":"value",
    "meta_data": {}
  }
}
{
  "result": "success",
  "meta":{count:1, total: 1, page: 1, per_page: 10, page_count: 1},
  "data": [{
    "object_id": "a3d182dc-04ba-4fba-96ff-d07580baff2b",
    "property":"value",
    "meta_data": {}
  }]
}

Normal data

  • status 200
{
  "result": "success",
  "data": {
    "object_id": "a3d182dc-04ba-4fba-96ff-d07580baff2b",
    "property":"value",
    "meta_data": {}
  }
}

Pagination data

  • status 200
{
  "result": "success",
  "data": [
    {
      "object_id": "fb172bdc-3f75-4404-9fd9-7e41d1fcf33a",
      "property": "value",
      "meta_data": {}
    },
    {
      "object_id": "8fd27037-af93-4390-a756-a26cbecff55d",
      "property": "value",
      "meta_data": {}
    },
    {
      "object_id": "ccc9e2f1-c69e-4f3d-afa7-563de5ce7c2b",
      "property": "value",
      "meta_data": {}
    }
  ],
  "meta":{
    "page": 1,
    "last_page": 10,
    "count": 100,
    "current": 10,
    "from": 1,
    "to": 10
  }
}

Create a resource failed

  • status 409: Resource conflict

    {
    "result": "failure",
    "message": "resource exists"
    }

Validation Error Message

  • status 422: Invalid parameter
{
  "result": "failure",
  "message":"Invalid parameter",
  "errors": [
      "Status must be in { \"complete\", \"cancelled\" }"
  ]
}
{
  "result": "failure",
  "message": "Invalid OrgGID provided."
}

Http Status

  • 200 OK - [*] The request has succeeded.
  • 400 INVALID REQUEST - [POST/PUT/PATCH] This response means that server could not understand the request due to invalid syntax.
  • 401 Unauthorized - [*] Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated"
  • 403 Forbidden - [*] The client does not have access rights to the content, i.e. they are unauthorized, so the server is rejecting to give a proper response.
  • 404 NOT FOUND - [*] The server cannot find the requested resource.
  • 405 Method Not Allowed - [*] The request method is known by the server but is not supported by the target resource.
  • 406 Not Acceptable - [*] This response is sent when the web server, after performing server-driven content negotiation, doesn't find any content following the criteria given by the user agent.
  • 409 Conflict - [POST/PUT/PATCH] This response is sent when a request conflicts with the current state of the server
  • 422 Unprocessable entity - [POST/PUT/PATCH] The request was well-formed but was unable to be followed due to semantic errors.
  • 429 Too Many Requests - [*] The user has sent too many requests in a given amount of time ("rate limiting").
  • 500 INTERNAL SERVER ERROR - [*] The server has encountered a situation it doesn't know how to handle.

Representational state transfer (REST)或者 RESTful
特点:结构清晰、符合标准、易于理解、扩展方便
REST这个词,是Roy Thomas Fielding在他2000年的博士论文中提出的。

什么是RESTful架构:

  1. 每一个URI代表一种资源;
  2. 客户端和服务器之间,传递这种资源的某种表现层;
  3. 客户端通过四个HTTP动词,对服务器端资源进行操作,实现"表现层状态转化"。

总结:

  • URL定位资源,用HTTP动词(GET,PUT,POST,DELETE,HEAD,OPTIONS)描述操作。
  • REST描述的是在网络中client和server的一种交互形式;
  • REST本身不实用,实用的是如何设计 RESTful API(REST风格的网络接口)
  • Server提供的RESTful API中,URL中只使用名词来指定资源,原则上不使用动词。
  • “资源”是REST架构或者说整个网络处理的核心

- 阅读剩余部分 -

问题

  • 在使用 $.val() 对一个input进行赋值时,只会解决 onchange事件
  • 在使用 v-on:change 对该事件进行绑定时,发现无法监听到 change 事件
  • v-model使用的是 input 事件而不是 change 导致 v-model 无法正常工作

解决办法

v-model 可以解决, 只需要在 change 事件中 触发一下 input 事件就好了。

$('#expire-date').on('change', function () {
  this.dispatchEvent(new Event('input'))
})

Success Message

{
  "code":0,
  "data":any  // any type of result
}

Failed Message

{
  "code":1, // 1-9999  >1
  "message":"string",  // error message
  "detail":any  // any detail of error message
}

Http Status Code HTTP Status Code

20x success status

Usually only use 200.
I only used 200 for success.

30x Redirect

4xx Client Response, Usually caused by the client side.

  • 400 for parameters error message
  • 422 for error message in process

5xx Server Response, Usually caused by the server side.