* GET /tickets/12/messages- Retrieves list of messages for ticket #12 * GET /tickets/12/messages/5- Retrieves message #5 for ticket #12 * POST /tickets/12/messages- Creates a new message in ticket #12 * PUT /tickets/12/messages/5- Updates message #5 for ticket #12 * PATCH /tickets/12/messages/5- Partially updates message #5 for ticket #12 * DELETE /tickets/12/messages/5- Deletes message #5 for ticket #12
其中,如果这种关联和资源独立,那么我们可以在资源的输出表示中保存相应资源的endpoint。然后API的使用者就可以通过点击链接找到相关的资源。如果关联和资源联系紧密。资源的输出表示就应该直接保存相应资源信息。(例如这里如果message资源是独立存在的,那么上面 GET /tickets/12/messages就会返回相应message的链接;相反的如果message不独立存在,他和ticket依附存在,则上面的API调用返回直接返回message信息)
* GET /ticketssort=-priority- Retrieves a list of tickets in descending order of priority * GET /ticketssort=-priority,created_at- Retrieves a list of tickets in descending order of priority. Within a specific priority, older tickets are ordered first
# A small example program for using the new getopt(1) program. # This program will only work with bash(1) # An similar program using the tcsh(1) script language can be found # as parse.tcsh
# Example input and output (from the bash prompt): # ./parse.bash -a par1 'another arg' --c-long 'wow!*\?' -cmore -b " very long " # Option a # Option c, no argument # Option c, argument `more' # Option b, argument ` very long ' # Remaining arguments: # --> `par1' # --> `another arg' # --> `wow!*\?'
# Note that we use `"$@"' to let each command-line parameter expand to a # separate word. The quotes around `$@' are essential! # We need TEMP as the `eval set --' would nuke the return value of getopt.
if [ $? != 0 ] ; thenecho"Terminating..." >&2 ; exit 1 ; fi
# Note the quotes around `$TEMP': they are essential! #set 会重新排列参数的顺序,也就是改变$1,$2...$n的值,这些值在getopt中重新排列过了 evalset -- "$TEMP"
#经过getopt的处理,下面处理具体选项。
whiletrue ; do case"$1"in -a|--a-long) echo"Option a" ; shift ;; -b|--b-long) echo"Option b, argument \`$2'" ; shift 2 ;; -c|--c-long) # c has an optional argument. As we are in quoted mode, # an empty parameter will be generated if its optional # argument is not found. case"$2"in "") echo"Option c, no argument"; shift 2 ;; *) echo"Option c, argument \`$2'" ; shift 2 ;; esac ;; --) shift ; break ;; *) echo"Internal error!" ; exit 1 ;; esac done echo"Remaining arguments:" for arg do echo'--> '"\`$arg'" ; done
比如我们使用
./test -a -b arg arg1 -c
你可以看到,命令行中多了个arg1参数,在经过getopt和set之后,命令行会变为: -a -b arg -c -- arg1 $1指向-a,$2指向-b,$3指向arg,$4指向-c,$5指向–,而多出的arg1则被放到了最后。