Äú¿ÉÒÔ¾èÖú£¬Ö§³ÖÎÒÃǵĹ«ÒæÊÂÒµ¡£

1Ôª 10Ôª 50Ôª





ÈÏÖ¤Â룺  ÑéÖ¤Âë,¿´²»Çå³þ?Çëµã»÷Ë¢ÐÂÑéÖ¤Âë ±ØÌî



  ÇóÖª ÎÄÕ ÎÄ¿â Lib ÊÓƵ iPerson ¿Î³Ì ÈÏÖ¤ ×Éѯ ¹¤¾ß ½²×ù Modeler   Code  
»áÔ±   
 
   
 
 
     
   
 ¶©ÔÄ
  ¾èÖú
RESTFul¼Ü¹¹Ïê½â
 
À´Ô´£ºÐ¡Ã«µÄºú˼ÂÒÏë ·¢²¼ÓÚ£º2014-12-17
  2906  次浏览      23
 

1 ʲôÊÇREST

RESTÈ«³ÆÊÇRepresentational State Transfer£¬ÖÐÎÄÒâ˼ÊDZíÊöÐÔ״̬תÒÆ¡£ ËüÊ״γöÏÖÔÚ2000ÄêRoy FieldingµÄ²©Ê¿ÂÛÎÄÖУ¬Roy FieldingÊÇ HTTP ¹æ·¶µÄÖ÷Òª±àдÕßÖ®Ò»¡£ ËûÔÚÂÛÎÄÖÐÌáµ½:¡°ÎÒÕâƪÎÄÕµÄд×÷Ä¿µÄ£¬¾ÍÊÇÏëÔÚ·ûºÏ¼Ü¹¹Ô­ÀíµÄÇ°ÌáÏ£¬Àí½âºÍÆÀ¹ÀÒÔÍøÂçΪ»ù´¡µÄÓ¦ÓÃÈí¼þµÄ¼Ü¹¹Éè¼Æ£¬µÃµ½Ò»¸ö¹¦ÄÜÇ¿¡¢ÐÔÄܺá¢ÊÊÒËͨÐŵļܹ¹¡£RESTÖ¸µÄÊÇÒ»×é¼Ü¹¹Ô¼ÊøÌõ¼þºÍÔ­Ôò¡£¡± Èç¹ûÒ»¸ö¼Ü¹¹·ûºÏRESTµÄÔ¼ÊøÌõ¼þºÍÔ­Ôò£¬ÎÒÃǾͳÆËüΪRESTful¼Ü¹¹¡£

REST±¾Éí²¢Ã»Óд´Ôìеļ¼Êõ¡¢×é¼þ»ò·þÎñ£¬¶øÒþ²ØÔÚRESTful±³ºóµÄÀíÄî¾ÍÊÇʹÓÃWebµÄÏÖÓÐÌØÕ÷ºÍÄÜÁ¦£¬ ¸üºÃµØʹÓÃÏÖÓÐWeb±ê×¼ÖеÄһЩ׼ÔòºÍÔ¼Êø¡£ËäÈ»REST±¾ÉíÊÜWeb¼¼ÊõµÄÓ°ÏìºÜÉ µ«ÊÇÀíÂÛÉÏREST¼Ü¹¹·ç¸ñ²¢²»ÊÇ°ó¶¨ÔÚHTTPÉÏ£¬Ö»²»¹ýÄ¿Ç°HTTPÊÇΨһÓëRESTÏà¹ØµÄʵÀý¡£ ËùÒÔÎÒÃÇÕâÀïÃèÊöµÄRESTÒ²ÊÇͨ¹ýHTTPʵÏÖµÄREST¡£

2 Àí½âRestFul

ÒªÀí½âRESTful¼Ü¹¹£¬ÐèÒªÀí½âRepresentational State TransferÕâ¸ö´Ê×éµ½µ×ÊÇʲôÒâ˼£¬ËüµÄÿһ¸ö´Ê¶¼ÓÐЩʲôº­Òå¡£ ÏÂÃæÎÒÃǽáºÏRESTÔ­Ôò£¬Î§ÈÆ×ÊÔ´Õ¹¿ªÌÖÂÛ£¬´Ó×ÊÔ´µÄ¶¨Òå¡¢»ñÈ¡¡¢±íÊö¡¢¹ØÁª¡¢×´Ì¬±äǨµÈ½Ç¶È£¬ÁоÙһЩ¹Ø¼ü¸ÅÄî²¢¼ÓÒÔ½âÊÍ:

1.×ÊÔ´ÓëURI

2.ͳһ×ÊÔ´½Ó¿Ú

3.×ÊÔ´µÄ±íÊö

4.×ÊÔ´µÄÁ´½Ó

5.״̬µÄתÒÆ

2.1 ×ÊÔ´ÓëURI

RESTÈ«³ÆÊDZíÊöÐÔ״̬תÒÆ£¬ÄǾ¿¾¹Ö¸µÄÊÇʲôµÄ±íÊö? ÆäʵָµÄ¾ÍÊÇ×ÊÔ´¡£ÈκÎÊÂÎֻҪÓб»ÒýÓõ½µÄ±ØÒª£¬Ëü¾ÍÊÇÒ»¸ö×ÊÔ´¡£×ÊÔ´¿ÉÒÔÊÇʵÌå(ÀýÈçÊÖ»úºÅÂë)£¬Ò²¿ÉÒÔÖ»ÊÇÒ»¸ö³éÏó¸ÅÄî(ÀýÈç¼ÛÖµ) ¡£ÏÂÃæÊÇһЩ×ÊÔ´µÄÀý×Ó:

1.ijÓû§µÄÊÖ»úºÅÂë

2.ijÓû§µÄ¸öÈËÐÅÏ¢

3.×î¶àÓû§¶©¹ºµÄGPRSÌײÍ

4.Á½¸ö²úÆ·Ö®¼äµÄÒÀÀµ¹Øϵ

5.ijÓû§¿ÉÒÔ°ìÀíµÄÓÅ»ÝÌײÍ

6.ijÊÖ»úºÅÂëµÄDZÔÚ¼ÛÖµ

ÒªÈÃÒ»¸ö×ÊÔ´¿ÉÒÔ±»Ê¶±ð£¬ÐèÒªÓиöΨһ±êʶ£¬ÔÚWebÖÐÕâ¸öΨһ±êʶ¾ÍÊÇURI(Uniform Resource Identifier)¡£ URI¼È¿ÉÒÔ¿´³ÉÊÇ×ÊÔ´µÄµØÖ·£¬Ò²¿ÉÒÔ¿´³ÉÊÇ×ÊÔ´µÄÃû³Æ¡£Èç¹ûijЩÐÅϢûÓÐʹÓÃURIÀ´±íʾ£¬ÄÇËü¾Í²»ÄÜËãÊÇÒ»¸ö×ÊÔ´£¬ Ö»ÄÜËãÊÇ×ÊÔ´µÄһЩÐÅÏ¢¶øÒÑ¡£URIµÄÉè¼ÆÓ¦¸Ã×ñÑ­¿ÉÑ°Ö·ÐÔÔ­Ôò£¬¾ßÓÐ×ÔÃèÊöÐÔ£¬ÐèÒªÔÚÐÎʽÉϸøÈËÒÔÖ±¾õÉϵĹØÁª¡£ÕâÀïÒÔgithubÍøվΪÀý£¬¸ø³öһЩ»¹Ëã²»´íµÄURI£º

1.https://github.com/git

2.https://github.com/git/git

3.https://github.com/git/git/blob/master/block-sha1/sha1.h

4.https://github.com/git/git/commit/e3af72cdafab5993d18fae056f87e1d675913d08

5.https://github.com/git/git/pulls

6.https://github.com/git/git/pulls?state=closed

7.https://github.com/git/git/compare/master¡­next

ÏÂÃæÈÃÎÒÃÇÀ´¿´¿´URIÉè¼ÆÉϵÄһЩ¼¼ÇÉ:

1.ʹÓÃ_»ò-À´ÈÃURI¿É¶ÁÐÔ¸üºÃ

Ôø¾­WebÉϵÄURI¶¼ÊDZùÀäµÄÊý×Ö»òÕßÎÞÒâÒåµÄ×Ö·û´®£¬µ«ÏÖÔÚÔ½À´Ô½¶àµÄÍøվʹÓÃ_»ò-À´·Ö¸ôһЩµ¥´Ê£¬ÈÃURI¿´ÉÏÈ¥¸üΪÈËÐÔ»¯¡£ ÀýÈç¹úÄڱȽϳöÃûµÄ¿ªÔ´ÖйúÉçÇø£¬ËüÉÏÃæµÄÐÂÎŵØÖ·¾Í²ÉÓÃÕâÖÖ·ç¸ñ£¬ Èçhttp://www.oschina.net/news/38119/oschina-translate-reward-plan¡£

2.ʹÓÃ/À´±íʾ×ÊÔ´µÄ²ã¼¶¹Øϵ

ÀýÈçÉÏÊö/git/git/commit/e3af72cdafab5993d18fae056f87e1d675913d08¾Í±íʾÁËÒ»¸ö¶à¼¶µÄ×ÊÔ´£¬ Ö¸µÄÊÇgitÓû§µÄgitÏîÄ¿µÄij´ÎÌá½»¼Ç¼,ÓÖÀýÈç/orders/2012/10¿ÉÒÔÓÃÀ´±íʾ2012Äê10ÔµĶ©µ¥¼Ç¼¡£

3.ʹÓÃ?ÓÃÀ´¹ýÂË×ÊÔ´

ºÜ¶àÈËÖ»ÊÇ°Ñ?¼òµ¥µÄµ±×öÊDzÎÊýµÄ´«µÝ£¬ºÜÈÝÒ×Ôì³ÉURI¹ýÓÚ¸´ÔÓ¡¢ÄÑÒÔÀí½â¡£¿ÉÒÔ°Ñ?ÓÃÓÚ¶Ô×ÊÔ´µÄ¹ýÂË£¬ ÀýÈç/git/git/pullsÓÃÀ´±íʾgitÏîÄ¿µÄËùÓÐÍÆÈëÇëÇ󣬶ø/pulls?state=closedÓÃÀ´±íʾgitÏîÄ¿ÖÐÒѾ­¹Ø±ÕµÄÍÆÈëÇëÇó£¬ ÕâÖÖURLͨ³£¶ÔÓ¦µÄÊÇһЩÌض¨Ìõ¼þµÄ²éѯ½á¹û»òËã·¨ÔËËã½á¹û¡£

4. ,»ò¿ÉÒÔÓÃÀ´±íʾͬ¼¶×ÊÔ´µÄ¹Øϵ

ÓÐʱºòÎÒÃÇÐèÒª±íʾͬ¼¶×ÊÔ´µÄ¹Øϵʱ£¬¿ÉÒÔʹÓÃ,»ò;À´½øÐзָÀýÈçÄÄÌìgithub¿ÉÒԱȽÏij¸öÎļþÔÚËæÒâÁ½´ÎÌá½»¼Ç¼֮¼äµÄ²îÒ죬 »òÐí¿ÉÒÔʹÓÃ/git/git /block-sha1/sha1.h/compare/e3af72cdafab5993d18fae056f87e1d675913d08; bd63e61bdf38e872d5215c07b264dcc16e4febca×÷ΪURI¡£ ²»¹ý£¬ÏÖÔÚgithubÊÇʹÓá­À´×öÕâ¸öÊÂÇéµÄ£¬ÀýÈç/git/git/compare/master¡­next¡£

2.2 ͳһ×ÊÔ´½Ó¿Ú

RESTFul¼Ü¹¹Ó¦¸Ã×ñѭͳһ½Ó¿ÚÔ­Ôò£¬Í³Ò»½Ó¿Ú°üº¬ÁËÒ»×éÊÜÏÞµÄÔ¤¶¨ÒåµÄ²Ù×÷£¬²»ÂÛʲôÑùµÄ×ÊÔ´£¬¶¼ÊÇͨ¹ýʹÓÃÏàͬµÄ½Ó¿Ú½øÐÐ×ÊÔ´µÄ·ÃÎÊ¡£½Ó¿ÚÓ¦¸ÃʹÓñê×¼µÄHTTP·½·¨ÈçGET£¬PUTºÍPOST£¬²¢×ñÑ­ÕâЩ·½·¨µÄÓïÒå¡£

Èç¹û°´ÕÕHTTP·½·¨µÄÓïÒåÀ´±©Â¶×ÊÔ´£¬ÄÇô½Ó¿Ú½«»áÓµÓа²È«ÐÔºÍÃݵÈÐÔµÄÌØÐÔ£¬ÀýÈçGETºÍHEADÇëÇó¶¼ÊÇ°²È«µÄ£¬ ÎÞÂÛÇëÇó¶àÉٴΣ¬¶¼²»»á¸Ä±ä·þÎñÆ÷״̬¡£¶øGET¡¢HEAD¡¢PUTºÍDELETEÇëÇó¶¼ÊÇÃݵȵģ¬ÎÞÂÛ¶Ô×ÊÔ´²Ù×÷¶àÉٴΣ¬ ½á¹û×ÜÊÇÒ»ÑùµÄ£¬ºóÃæµÄÇëÇó²¢²»»á²úÉú±ÈµÚÒ»´Î¸ü¶àµÄÓ°Ïì¡£

ÏÂÃæÁгöÁËGET£¬DELETE£¬PUTºÍPOSTµÄµäÐÍÓ÷¨:

GET

°²È«ÇÒÃݵÈ

»ñÈ¡±íʾ

±ä¸üʱ»ñÈ¡±íʾ£¨»º´æ£©

200£¨OK£© - ±íʾÒÑÔÚÏìÓ¦Öз¢³ö

204£¨ÎÞÄÚÈÝ£© - ×ÊÔ´Óпձíʾ

301£¨Moved Permanently£© - ×ÊÔ´µÄURIÒѱ»¸üÐÂ

303£¨See Other£© - ÆäËû£¨È磬¸ºÔؾùºâ£©

304£¨not modified£©- ×ÊԴδ¸ü¸Ä£¨»º´æ£©

400 £¨bad request£©- Ö¸´ú»µÇëÇó£¨È磬²ÎÊý´íÎó£©

404 £¨not found£©- ×ÊÔ´²»´æÔÚ

406 £¨not acceptable£©- ·þÎñ¶Ë²»Ö§³ÖËùÐè±íʾ

500 £¨internal server error£©- ͨÓôíÎóÏìÓ¦

503 £¨Service Unavailable£©- ·þÎñ¶Ëµ±Ç°ÎÞ·¨´¦ÀíÇëÇó

POST

²»°²È«ÇÒ²»ÃݵÈ

ʹÓ÷þÎñ¶Ë¹ÜÀíµÄ£¨×Ô¶¯²úÉú£©µÄʵÀýºÅ´´½¨×ÊÔ´

´´½¨×Ó×ÊÔ´

²¿·Ö¸üÐÂ×ÊÔ´

Èç¹ûûÓб»Ð޸ģ¬Ôò²»¹ý¸üÐÂ×ÊÔ´£¨ÀÖ¹ÛËø£©

200£¨OK£©- Èç¹ûÏÖÓÐ×ÊÔ´Òѱ»¸ü¸Ä

201£¨created£©- Èç¹ûÐÂ×ÊÔ´±»´´½¨

202£¨accepted£©- ÒѽÓÊÜ´¦ÀíÇëÇóµ«ÉÐδÍê³É£¨Òì²½´¦Àí£©

301£¨Moved Permanently£©- ×ÊÔ´µÄURI±»¸üÐÂ

303£¨See Other£©- ÆäËû£¨È磬¸ºÔؾùºâ£©

400£¨bad request£©- Ö¸´ú»µÇëÇó

404 £¨not found£©- ×ÊÔ´²»´æÔÚ

406 £¨not acceptable£©- ·þÎñ¶Ë²»Ö§³ÖËùÐè±íʾ

409 £¨conflict£©- ͨÓóåÍ»

412 £¨Precondition Failed£©- Ç°ÖÃÌõ¼þʧ°Ü£¨ÈçÖ´ÐÐÌõ¼þ¸üÐÂʱµÄ³åÍ»£©

415 £¨unsupported media type£©- ½ÓÊܵ½µÄ±íʾ²»ÊÜÖ§³Ö

500 £¨internal server error£©- ͨÓôíÎóÏìÓ¦

503 £¨Service Unavailable£©- ·þÎñµ±Ç°ÎÞ·¨´¦ÀíÇëÇó

PUT

²»°²È«µ«ÃݵÈ

Óÿͻ§¶Ë¹ÜÀíµÄʵÀýºÅ´´½¨Ò»¸ö×ÊÔ´

ͨ¹ýÌæ»»µÄ·½Ê½¸üÐÂ×ÊÔ´

Èç¹ûδ±»Ð޸ģ¬Ôò¸üÐÂ×ÊÔ´£¨ÀÖ¹ÛËø£©

200 £¨OK£©- Èç¹ûÒÑ´æÔÚ×ÊÔ´±»¸ü¸Ä

201 £¨created£©- Èç¹ûÐÂ×ÊÔ´±»´´½¨

301£¨Moved Permanently£©- ×ÊÔ´µÄURIÒѸü¸Ä

303 £¨See Other£©- ÆäËû£¨È磬¸ºÔؾùºâ£©

400 £¨bad request£©- Ö¸´ú»µÇëÇó

404 £¨not found£©- ×ÊÔ´²»´æÔÚ

406 £¨not acceptable£©- ·þÎñ¶Ë²»Ö§³ÖËùÐè±íʾ

409 £¨conflict£©- ͨÓóåÍ»

412 £¨Precondition Failed£©- Ç°ÖÃÌõ¼þʧ°Ü£¨ÈçÖ´ÐÐÌõ¼þ¸üÐÂʱµÄ³åÍ»£©

415 £¨unsupported media type£©- ½ÓÊܵ½µÄ±íʾ²»ÊÜÖ§³Ö

500 £¨internal server error£©- ͨÓôíÎóÏìÓ¦

503 £¨Service Unavailable£©- ·þÎñµ±Ç°ÎÞ·¨´¦ÀíÇëÇó

DELETE

²»°²È«µ«ÃݵÈ

ɾ³ý×ÊÔ´

200 £¨OK£©- ×ÊÔ´Òѱ»É¾³ý

301 £¨Moved Permanently£©- ×ÊÔ´µÄURIÒѸü¸Ä

303 £¨See Other£©- ÆäËû£¬È縺Ôؾùºâ

400 £¨bad request£©- Ö¸´ú»µÇëÇó

404 £¨not found£©- ×ÊÔ´²»´æÔÚ

409 £¨conflict£©- ͨÓóåÍ»

500 £¨internal server error£©- ͨÓôíÎóÏìÓ¦

503 £¨Service Unavailable£©- ·þÎñ¶Ëµ±Ç°ÎÞ·¨´¦ÀíÇëÇó

ÏÂÃæÎÒÃÇÀ´¿´Ò»Ð©Êµ¼ùÖг£¼ûµÄÎÊÌâ:

POSTºÍPUTÓÃÓÚ´´½¨×ÊԴʱÓÐʲôÇø±ð?

POSTºÍPUTÔÚ´´½¨×ÊÔ´µÄÇø±ðÔÚÓÚ£¬Ëù´´½¨µÄ×ÊÔ´µÄÃû³Æ(URI)ÊÇ·ñÓÉ¿Í»§¶Ë¾ö¶¨¡£ ÀýÈçΪÎҵIJ©ÎÄÔö¼ÓÒ»¸öjavaµÄ·ÖÀ࣬Éú³ÉµÄ·¾¶¾ÍÊÇ·ÖÀàÃû/categories/java£¬ÄÇô¾Í¿ÉÒÔ²ÉÓÃPUT·½·¨¡£ ²»¹ýºÜ¶àÈËÖ±½Ó°ÑPOST¡¢GET¡¢PUT¡¢DELETEÖ±½Ó¶ÔÓ¦ÉÏCRUD£¬ÀýÈçÔÚÒ»¸öµäÐ͵ÄrailsʵÏÖµÄRESTFulÓ¦ÓÃÖоÍÊÇÕâô×öµÄ¡£ ÎÒÈÏΪ£¬ÕâÊÇÒòΪrailsĬÈÏʹÓ÷þÎñ¶ËÉú³ÉµÄID×÷ΪURIµÄÔµ¹Ê£¬¶ø²»ÉÙÈ˾ÍÊÇͨ¹ýrailsʵ¼ùRESTµÄ£¬ËùÒÔºÜÈÝÒ×Ôì³ÉÕâÖÖÎó½â¡£

¿Í»§¶Ë²»Ò»¶¨¶¼Ö§³ÖÕâЩHTTP·½·¨°É?

µÄÈ·ÓÐÕâÖÖÇé¿ö£¬ÌرðÊÇһЩ±È½Ï¹ÅÀϵĻùÓÚä¯ÀÀÆ÷µÄ¿Í»§¶Ë£¬Ö»ÄÜÖ§³ÖGETºÍPOSTÁ½ÖÖ·½·¨¡£ ÔÚʵ¼ùÉÏ£¬¿Í»§¶ËºÍ·þÎñ¶Ë¶¼¿ÉÄÜÐèÒª×öһЩÍ×Э¡£ÀýÈçrails¿ò¼Ü¾ÍÖ§³Öͨ¹ýÒþ²Ø²ÎÊý_method=DELETEÀ´´«µÝÕæʵµÄÇëÇó·½·¨, ¶øÏñBackboneÕâÑùµÄ¿Í»§¶ËMVC¿ò¼ÜÔòÔÊÐí´«µÝ_method´«ÊäºÍÉèÖÃX-HTTP-Method-OverrideÍ·À´¹æ±ÜÕâ¸öÎÊÌâ¡£

ͳһ½Ó¿ÚÊÇ·ñÒâζ×Ų»ÄÜÀ©Õ¹´øÌØÊâÓïÒåµÄ·½·¨?

ͳһ½Ó¿Ú²¢²»×èÖ¹ÄãÀ©Õ¹·½·¨£¬Ö»Òª·½·¨¶Ô×ÊÔ´µÄ²Ù×÷ÓÐמßÌåµÄ¡¢¿Éʶ±ðµÄÓïÒå¼´¿É£¬²¢Äܹ»±£³ÖÕû¸ö½Ó¿ÚµÄͳһÐÔ¡£ ÏñWebDAV¾Í¶ÔHTTP·½·¨½øÐÐÁËÀ©Õ¹£¬Ôö¼ÓÁËLOCK¡¢UPLOCKµÈ·½·¨¡£¶øgithubµÄAPIÔòÖ§³ÖʹÓÃPATCH·½·¨À´½øÐÐissueµÄ¸üУ¬ÀýÈç:

PATCH /repos/:owner/:repo/issues/:number

²»¹ý£¬ÐèҪעÒâµÄÊÇ£¬ÏñPATCHÕâÖÖ²»ÊÇHTTP±ê×¼·½·¨µÄ£¬·þÎñ¶ËÐèÒª¿¼ÂÇ¿Í»§¶ËÊÇ·ñÄܹ»Ö§³ÖµÄÎÊÌâ¡£

ͳһ×ÊÔ´½Ó¿Ú¶ÔURIÓÐʲôָµ¼ÒâÒå?

ͳһ×ÊÔ´½Ó¿ÚÒªÇóʹÓñê×¼µÄHTTP·½·¨¶Ô×ÊÔ´½øÐвÙ×÷£¬ËùÒÔURIÖ»Ó¦¸ÃÀ´±íʾ×ÊÔ´µÄÃû³Æ£¬¶ø²»Ó¦¸Ã°üÀ¨×ÊÔ´µÄ²Ù×÷¡£ ͨË×À´Ëµ£¬URI²»Ó¦¸ÃʹÓö¯×÷À´ÃèÊö¡£ÀýÈ磬ÏÂÃæÊÇһЩ²»·ûºÏͳһ½Ó¿ÚÒªÇóµÄURI:

1.GET /getUser/1

2.POST /createUser

3.PUT /updateUser/1

4.DELETE /deleteUser/1

Èç¹ûGETÇëÇóÔö¼Ó¼ÆÊýÆ÷£¬ÕâÊÇ·ñÎ¥·´°²È«ÐÔ?

°²È«ÐÔ²»´ú±íÇëÇó²»²úÉú¸±×÷Óã¬ÀýÈçÏñºÜ¶àAPI¿ª·¢Æ½Ì¨£¬¶¼¶ÔÇëÇóÁ÷Á¿×öÏÞÖÆ¡£Ïñgithub£¬¾Í»áÏÞÖÆûÓÐÈÏÖ¤µÄÇëÇóÿСʱֻÄÜÇëÇó60´Î¡£ µ«¿Í»§¶Ë²»ÊÇΪÁË×·Çó¸±×÷Óöø·¢³öÕâЩGET»òHEADÇëÇóµÄ,²úÉú¸±×÷ÓÃÊÇ·þÎñ¶Ë¡°×Ô×÷Ö÷ÕÅ¡±µÄ¡£ ÁíÍ⣬·þÎñ¶ËÔÚÉè¼Æʱ£¬Ò²²»Ó¦¸ÃÈø±×÷ÓÃÌ«´ó£¬ÒòΪ¿Í»§¶ËÈÏΪÕâЩÇëÇóÊDz»»á²úÉú¸±×÷Óõġ£

Ö±½ÓºöÊÓ»º´æ¿ÉÈ¡Âð?

¼´Ê¹Äã°´¸÷¸ö¶¯´ÊµÄÔ­±¾ÒâͼÀ´Ê¹ÓÃËüÃÇ£¬ÄãÈÔ¿ÉÒÔÇáÒ×½ûÖ¹»º´æ»úÖÆ¡£ ×î¼òµ¥µÄ×ö·¨¾ÍÊÇÔÚÄãµÄHTTPÏìÓ¦ÀïÔö¼ÓÕâÑùÒ»¸ö±¨Í·£º Cache-control: no-cache¡£ µ«ÊÇ£¬Í¬Ê±ÄãÒ²¶ÔʧȥÁ˸ßЧµÄ»º´æÓëÔÙÑéÖ¤µÄÖ§³Ö(ʹÓÃEtagµÈ»úÖÆ)¡£ ¶ÔÓÚ¿Í»§¶ËÀ´Ëµ£¬ÔÚΪһ¸öRESTʽ·þÎñʵÏÖ³ÌÐò¿Í»§¶Ëʱ£¬Ò²Ó¦¸Ã³ä·ÖÀûÓÃÏÖÓеĻº´æ»úÖÆ£¬ÒÔÃâÿ´Î¶¼ÖØлñÈ¡±íʾ¡£

ÏìÓ¦´úÂëµÄ´¦ÀíÓбØÒªÂð?

ÈçÉÏͼËùʾ£¬HTTPµÄÏìÓ¦´úÂë¿ÉÓÃÓÚÓ¦¸¶²»Í¬³¡ºÏ£¬ÕýȷʹÓÃÕâЩ״̬´úÂëÒâζ×Å¿Í»§¶ËÓë·þÎñÆ÷¿ÉÒÔÔÚÒ»¸ö¾ß±¸½Ï·á¸»ÓïÒåµÄ²ã´ÎÉϽøÐйµÍ¨¡£ ÀýÈ磬201£¨¡°Created¡±£©ÏìÓ¦´úÂë±íÃ÷ÒѾ­´´½¨ÁËÒ»¸öеÄ×ÊÔ´£¬ÆäURIÔÚLocationÏìÓ¦±¨Í·Àï¡£ ¼ÙÈçÄã²»ÀûÓÃHTTP״̬´úÂë·á¸»µÄÓ¦ÓÃÓïÒ壬ÄÇôÄ㽫´íʧÌá¸ßÖØÓÃÐÔ¡¢ÔöÇ¿»¥²Ù×÷ÐÔºÍÌáÉýËÉñîºÏÐԵĻú»á¡£ Èç¹ûÕâЩËùνµÄRESTFulÓ¦ÓñØÐëͨ¹ýÏìӦʵÌå²ÅÄܸø³ö´íÎóÐÅÏ¢£¬ÄÇôSOAP¾ÍÊÇÕâÑùµÄÁË£¬Ëü¾ÍÄܹ»Âú×ãÁË¡£

2.3 ×ÊÔ´µÄ±íÊö

ÉÏÃæÌáµ½£¬¿Í»§¶Ëͨ¹ýHTTP·½·¨¿ÉÒÔ»ñÈ¡×ÊÔ´£¬ÊÇ°É? ²»£¬È·ÇеÄ˵£¬¿Í»§¶Ë»ñÈ¡µÄÖ»ÊÇ×ÊÔ´µÄ±íÊö¶øÒÑ¡£ ×ÊÔ´ÔÚÍâ½çµÄ¾ßÌå³ÊÏÖ£¬¿ÉÒÔÓжàÖÖ±íÊö(»ò³ÉΪ±íÏÖ¡¢±íʾ)ÐÎʽ,ÔÚ¿Í»§¶ËºÍ·þÎñ¶ËÖ®¼ä´«Ë͵ÄÒ²ÊÇ×ÊÔ´µÄ±íÊö£¬¶ø²»ÊÇ×ÊÔ´±¾Éí¡£ ÀýÈçÎı¾×ÊÔ´¿ÉÒÔ²ÉÓÃhtml¡¢xml¡¢jsonµÈ¸ñʽ£¬Í¼Æ¬¿ÉÒÔʹÓÃPNG»òJPGÕ¹ÏÖ³öÀ´¡£ ×ÊÔ´µÄ±íÊö°üÀ¨Êý¾ÝºÍÃèÊöÊý¾ÝµÄÔªÊý¾Ý£¬ÀýÈ磬HTTPÍ·¡°Content-Type¡± ¾ÍÊÇÕâÑùÒ»¸öÔªÊý¾ÝÊôÐÔ¡£

ÄÇô¿Í»§¶ËÈçºÎÖªµÀ·þÎñ¶ËÌṩÄÄÖÖ±íÊöÐÎʽÄØ?

´ð°¸ÊÇ¿ÉÒÔͨ¹ýHTTPÄÚÈÝЭÉÌ£¬¿Í»§¶Ë¿ÉÒÔͨ¹ýAcceptÍ·ÇëÇóÒ»ÖÖÌض¨¸ñʽµÄ±íÊö£¬·þÎñ¶ËÔòͨ¹ýContent-Type¸æËß¿Í»§¶Ë×ÊÔ´µÄ±íÊöÐÎʽ¡£

ÒÔgithubΪÀý£¬ÇëÇóij×éÖ¯×ÊÔ´µÄjson¸ñʽµÄ±íÊöÐÎʽ:

¼ÙÈçgithubÒ²Äܹ»Ö§³Öxml¸ñʽµÄ±íÊö¸ñʽ£¬ÄÇô½á¹û¾ÍÊÇÕâÑùµÄ:

ÏÂÃæÎÒÃÇÀ´¿´Ò»Ð©Êµ¼ùÉϳ£¼ûµÄÉè¼Æ:

1.ÔÚURIÀï±ß´øÉÏ°æ±¾ºÅ

ÓÐЩAPIÔÚURIÀï±ß´øÉÏ°æ±¾ºÅ£¬ÀýÈç:

1.http://api.example.com/1.0/foo

2.http://api.example.com/1.2/foo

3.http://api.example.com/2.0/foo

Èç¹ûÎÒÃÇ°Ñ°æ±¾ºÅÀí½â³É×ÊÔ´µÄ²»Í¬±íÊöÐÎʽµÄ»°£¬¾ÍÓ¦¸ÃÖ»ÊÇÓÃÒ»¸öURL£¬²¢Í¨¹ýAcceptÍ·²¿À´Çø·Ö£¬»¹ÊÇÒÔgithubΪÀý,ËüµÄAcceptµÄÍêÕû¸ñʽÊÇ:application/vnd.github[.version].param[+json]

¶ÔÓÚv3°æ±¾µÄ»°£¬¾ÍÊÇAccept: application/vnd.github.v3¡£¶ÔÓÚÉÏÃæµÄÀý×Ó£¬Í¬Àí¿ÉÒÔʹÓÃʹÓÃÏÂÃæµÄÍ·²¿:

1.Accept: vnd.example-com.foo+json; version=1.0

2.Accept: vnd.example-com.foo+json; version=1.2

3.Accept: vnd.example-com.foo+json; version=2.0

4.ʹÓÃURIºó׺À´Çø·Ö±íÊö¸ñʽ

Ïñrails¿ò¼Ü£¬¾ÍÖ§³ÖʹÓÃ/users.xml»ò/users.jsonÀ´Çø·Ö²»Í¬µÄ¸ñʽ¡£ ÕâÑùµÄ·½Ê½¶ÔÓÚ¿Í»§¶ËÀ´Ëµ£¬ÎÞÒÉÊǸüΪֱ¹Û£¬µ«»ìÏýÁË×ÊÔ´µÄÃû³ÆºÍ×ÊÔ´µÄ±íÊöÐÎʽ¡£ ÎÒ¸öÈËÈÏΪ£¬»¹ÊÇÓ¦¸ÃÓÅÏÈʹÓÃÄÚÈÝЭÉÌÀ´Çø·Ö±íÊö¸ñʽ¡£

5. ÈçºÎ´¦Àí²»Ö§³ÖµÄ±íÊö¸ñʽ

µ±·þÎñÆ÷²»Ö§³ÖËùÇëÇóµÄ±íÊö¸ñʽ£¬ÄÇôӦ¸ÃÔõô°ì£¿Èô·þÎñÆ÷²»Ö§³Ö£¬ËüÓ¦¸Ã·µ»ØÒ»¸öHTTP 406ÏìÓ¦£¬±íʾ¾Ü¾ø´¦Àí¸ÃÇëÇó¡£ÏÂÃæÒÔgithubΪÀý£¬Õ¹Ê¾ÁËÒ»¸öÇëÇóXML±íÊö×ÊÔ´µÄ½á¹û£º

2.4 ×ÊÔ´µÄÁ´½Ó

ÎÒÃÇÖªµÀRESTÊÇʹÓñê×¼µÄHTTP·½·¨À´²Ù×÷×ÊÔ´µÄ£¬µ«½ö½öÒò´Ë¾ÍÀí½â³É´øCURDµÄWebÊý¾Ý¿â¼Ü¹¹¾ÍÌ«¹ýÓÚ¼òµ¥ÁË¡£ ÕâÖÖ·´Ä£Ê½ºöÂÔÁËÒ»¸öºËÐĸÅÄî: ¡°³¬Ã½Ìå¼´Ó¦ÓÃ״̬ÒýÇ棨hypermedia as the engine of application state£©¡±¡£ ³¬Ã½ÌåÊÇʲô? µ±Äãä¯ÀÀWebÍøҳʱ£¬´ÓÒ»¸öÁ¬½ÓÌøµ½Ò»¸öÒ³Ã棬ÔÙ´ÓÁíÒ»¸öÁ¬½ÓÌøµ½ÁíÍâÒ»¸öÒ³Ã棬¾ÍÊÇÀûÓÃÁ˳¬Ã½ÌåµÄ¸ÅÄî: °ÑÒ»¸ö¸ö°Ñ×ÊÔ´Á´½ÓÆðÀ´.

Òª´ïµ½Õâ¸öÄ¿µÄ£¬¾ÍÒªÇóÔÚ±íÊö¸ñʽÀï±ß¼ÓÈëÁ´½ÓÀ´Òýµ¼¿Í»§¶Ë¡£ÔÚ¡¶RESTFul Web Services¡·Ò»ÊéÖУ¬×÷Õß°ÑÕâÖÖ¾ßÓÐÁ´½ÓµÄÌØÐÔ³ÉΪÁ¬Í¨ÐÔ¡£ÏÂÃæÎÒÃǾßÌåÀ´¿´Ò»Ð©Àý×Ó¡£

ÏÂÃæչʾµÄÊÇgithub»ñȡij¸ö×é֯ϵÄÏîÄ¿ÁбíµÄÇëÇ󣬿ÉÒÔ¿´µ½ÔÚÏìӦͷÀï±ßÔö¼ÓLinkÍ·¸æËß¿Í»§¶ËÔõô·ÃÎÊÏÂÒ»Ò³ºÍ×îºóÒ»Ò³µÄ¼Ç¼¡£ ¶øÔÚÏìÓ¦ÌåÀï±ß£¬ÓÃurlÀ´Á´½ÓÏîÄ¿ËùÓÐÕߺÍÏîÄ¿µØÖ·¡£

ÓÖÀýÈçÏÂÃæÕâ¸öÀý×Ó£¬´´½¨¶©µ¥ºóͨ¹ýÁ´½ÓÒýµ¼¿Í»§¶ËÈçºÎÈ¥¸¶¿î¡£

ÉÏÃæµÄÀý×ÓչʾÁËÈçºÎʹÓó¬Ã½ÌåÀ´ÔöÇ¿×ÊÔ´µÄÁ¬Í¨ÐÔ¡£ºÜ¶àÈËÔÚÉè¼ÆRESTFul¼Ü¹¹Ê±£¬Ê¹Óúܶàʱ¼äÀ´Ñ°ÕÒƯÁÁµÄURI,¶øºöÂÔÁ˳¬Ã½Ìå¡£ËùÒÔ£¬Ó¦¸Ã¶à»¨Ò»Ð©Ê±¼äÀ´¸ø×ÊÔ´µÄ±íÊöÌṩÁ´½Ó£¬¶ø²»ÊÇרעÓÚ¡°×ÊÔ´µÄCRUD¡±¡£

2.5 ״̬µÄתÒÆ

ÓÐÁËÉÏÃæµÄÆ̵棬ÔÙÌÖÂÛRESTÀï±ßµÄ״̬תÒƾͻáºÜÈÝÒ×Àí½âÁË¡£ ²»¹ý£¬ÎÒÃÇÏÈÀ´ÌÖÂÛÒ»ÏÂRESTÔ­ÔòÖеÄÎÞ״̬ͨÐÅÔ­Ôò¡£³õ¿´Ò»Ï£¬ºÃÏñ×ÔÏàì¶ÜÁË£¬¼ÈÈ»ÎÞ״̬£¬ºÎÀ´×´Ì¬×ªÒÆһ˵?

Æäʵ£¬ÕâÀï˵µÄÎÞ״̬ͨÐÅÔ­Ôò£¬²¢²»ÊÇ˵¿Í»§¶ËÓ¦Óò»ÄÜÓÐ״̬£¬¶øÊÇÖ¸·þÎñ¶Ë²»Ó¦¸Ã±£´æ¿Í»§¶Ë״̬¡£

2.5.1 Ó¦ÓÃ״̬Óë×ÊԴ״̬

ʵ¼ÊÉÏ£¬×´Ì¬Ó¦¸ÃÇø·ÖÓ¦ÓÃ״̬ºÍ×ÊԴ״̬£¬¿Í»§¶Ë¸ºÔðά»¤Ó¦ÓÃ״̬£¬¶ø·þÎñ¶Ëά»¤×ÊԴ״̬¡£ ¿Í»§¶ËÓë·þÎñ¶ËµÄ½»»¥±ØÐëÊÇÎÞ״̬µÄ£¬²¢ÔÚÿһ´ÎÇëÇóÖаüº¬´¦Àí¸ÃÇëÇóËùÐèµÄÒ»ÇÐÐÅÏ¢¡£ ·þÎñ¶Ë²»ÐèÒªÔÚÇëÇó¼ä±£ÁôÓ¦ÓÃ״̬£¬Ö»ÓÐÔÚ½ÓÊܵ½Êµ¼ÊÇëÇóµÄʱºò£¬·þÎñ¶Ë²Å»á¹Ø×¢Ó¦ÓÃ״̬¡£ ÕâÖÖÎÞ״̬ͨÐÅÔ­Ôò£¬Ê¹µÃ·þÎñ¶ËºÍÖнéÄܹ»Àí½â¶ÀÁ¢µÄÇëÇóºÍÏìÓ¦¡£ ÔÚ¶à´ÎÇëÇóÖУ¬Í¬Ò»¿Í»§¶ËÒ²²»ÔÙÐèÒªÒÀÀµÓÚͬһ·þÎñÆ÷£¬·½±ãʵÏָ߿ÉÀ©Õ¹ºÍ¸ß¿ÉÓÃÐԵķþÎñ¶Ë¡£

µ«ÓÐʱºòÎÒÃÇ»á×ö³öÎ¥·´ÎÞ״̬ͨÐÅÔ­ÔòµÄÉè¼Æ£¬ÀýÈçÀûÓÃCookie¸ú×Ùij¸ö·þÎñ¶Ë»á»°×´Ì¬£¬³£¼ûµÄÏñJ2EEÀï±ßµÄJSESSIONID¡£ ÕâÒâζ×Å£¬ä¯ÀÀÆ÷Ëæ¸÷´ÎÇëÇó·¢³öÈ¥µÄCookieÊDZ»ÓÃÓÚ¹¹½¨»á»°×´Ì¬µÄ¡£ µ±È»£¬Èç¹ûCookie±£´æµÄÊÇһЩ·þÎñÆ÷²»ÒÀÀµÓڻỰ״̬¼´¿ÉÑéÖ¤µÄÐÅÏ¢£¨±ÈÈçÈÏÖ¤ÁîÅÆ£©£¬ÕâÑùµÄCookieÒ²ÊÇ·ûºÏRESTÔ­ÔòµÄ¡£

2.5.2 Ó¦ÓÃ״̬µÄתÒÆ

״̬תÒƵ½ÕâÀïÒѾ­ºÜºÃÀí½âÁË£¬ ¡°»á»°¡±×´Ì¬²»ÊÇ×÷Ϊ×ÊԴ״̬±£´æÔÚ·þÎñ¶ËµÄ£¬¶øÊDZ»¿Í»§¶Ë×÷ΪӦÓÃ״̬½øÐиú×ٵġ£¿Í»§¶ËÓ¦ÓÃ״̬ÔÚ·þÎñ¶ËÌṩµÄ³¬Ã½ÌåµÄÖ¸ÒýÏ·¢Éú±äǨ¡£·þÎñ¶Ëͨ¹ý³¬Ã½Ìå¸æËß¿Í»§¶Ëµ±Ç°×´Ì¬ÓÐÄÄЩºóÐø״̬¿ÉÒÔ½øÈë¡£ ÕâЩÀàËÆ¡°ÏÂÒ»Ò³¡±Ö®ÀàµÄÁ´½ÓÆðµÄ¾ÍÊÇÕâÖÖÍƽø״̬µÄ×÷ÓèCÖ¸ÒýÄãÈçºÎ´Óµ±Ç°×´Ì¬½øÈëÏÂÒ»¸ö¿ÉÄܵÄ״̬¡£

3 ×ܽá

ÏÖÔڹ㶫XXX°æ±¾¡¢XXXµÈÏîÄ¿ÖоùʹÓô«Í³µÄRPC¡¢SOAP·½Ê½µÄWeb·þÎñ£¬¶øÒƶ¯ÄÏ·½»ùµØXXXXÏîÄ¿µÄºǫ́, ËäÈ»²ÉÓÃÁËJSON¸ñʽ½øÐн»»¥£¬µ«»¹ÊÇÊôÓÚRPC·ç¸ñµÄ¡£±¾ÎÄ´Ó×ÊÔ´µÄ¶¨Òå¡¢»ñÈ¡¡¢±íÊö¡¢¹ØÁª¡¢×´Ì¬±äǨµÈ½Ç¶È£¬ ÊÔͼ¿ìËÙÀí½âRESTFul¼Ü¹¹±³ºóµÄ¸ÅÄî¡£RESTFul¼Ü¹¹Ó봫ͳµÄRPC¡¢SOAPµÈ·½Ê½ÔÚÀíÄîÉÏÓкܴóµÄ²»Í¬£¬Ï£Íû±¾ÎÄÄܶԸ÷λÀí½âRESTÓÐËù°ïÖú¡£

   
2906 ´Îä¯ÀÀ       23
Ïà¹ØÎÄÕÂ

ÆóÒµ¼Ü¹¹¡¢TOGAFÓëArchiMate¸ÅÀÀ
¼Ü¹¹Ê¦Ö®Â·-ÈçºÎ×öºÃÒµÎñ½¨Ä££¿
´óÐÍÍøÕ¾µçÉÌÍøÕ¾¼Ü¹¹°¸ÀýºÍ¼¼Êõ¼Ü¹¹µÄʾÀý
ÍêÕûµÄArchimateÊÓµãÖ¸ÄÏ£¨°üÀ¨Ê¾Àý£©
Ïà¹ØÎĵµ

Êý¾ÝÖÐ̨¼¼Êõ¼Ü¹¹·½·¨ÂÛÓëʵ¼ù
ÊÊÓÃArchiMate¡¢EA ºÍ iSpace½øÐÐÆóÒµ¼Ü¹¹½¨Ä£
ZachmanÆóÒµ¼Ü¹¹¿ò¼Ü¼ò½é
ÆóÒµ¼Ü¹¹ÈÃSOAÂäµØ
Ïà¹Ø¿Î³Ì

ÔÆƽ̨Óë΢·þÎñ¼Ü¹¹Éè¼Æ
ÖÐ̨սÂÔ¡¢ÖÐ̨½¨ÉèÓëÊý×ÖÉÌÒµ
ÒÚ¼¶Óû§¸ß²¢·¢¡¢¸ß¿ÉÓÃϵͳ¼Ü¹¹
¸ß¿ÉÓ÷ֲ¼Ê½¼Ü¹¹Éè¼ÆÓëʵ¼ù
×îл¼Æ»®
Èí¼þ¼Ü¹¹Éè¼Æ·½·¨¡¢°¸ÀýÓëʵ¼ù 8-23[ÌØ»Ý]
LinuxÄں˱à³Ì¼°É豸Çý¶¯ 8-15[±±¾©]
Python¡¢Êý¾Ý·ÖÎöÓë»úÆ÷ѧϰ 8-23[ÌØ»Ý]
ǶÈëʽÈí¼þ¼Ü¹¹Éè¼Æ 8-22[ÏßÉÏ]
QTÓ¦Óÿª·¢ 9-5[±±¾©]

ר¼ÒÊӽǿ´ITÓë¼Ü¹¹
Èí¼þ¼Ü¹¹Éè¼Æ
ÃæÏò·þÎñÌåϵ¼Ü¹¹ºÍÒµÎñ×é¼þ
ÈËÈËÍøÒƶ¯¿ª·¢¼Ü¹¹
¼Ü¹¹¸¯»¯Ö®ÃÕ
̸ƽ̨¼´·þÎñPaaS


ÃæÏòÓ¦Óõļܹ¹Éè¼Æʵ¼ù
µ¥Ôª²âÊÔ+Öع¹+Éè¼Æģʽ
Èí¼þ¼Ü¹¹Ê¦¡ª¸ß¼¶Êµ¼ù
Èí¼þ¼Ü¹¹Éè¼Æ·½·¨¡¢°¸ÀýÓëʵ¼ù
ǶÈëʽÈí¼þ¼Ü¹¹Éè¼Æ¡ª¸ß¼¶Êµ¼ù
SOAÌåϵ½á¹¹Êµ¼ù


Èñ°²¿Æ¼¼ Èí¼þ¼Ü¹¹Éè¼Æ·½·¨
³É¶¼ ǶÈëʽÈí¼þ¼Ü¹¹Éè¼Æ
ÉϺ£Æû³µ ǶÈëʽÈí¼þ¼Ü¹¹Éè¼Æ
±±¾© Èí¼þ¼Ü¹¹Éè¼Æ
ÉϺ£ Èí¼þ¼Ü¹¹Éè¼Æ°¸ÀýÓëʵ¼ù
±±¾© ¼Ü¹¹Éè¼Æ·½·¨°¸ÀýÓëʵ¼ù
ÉîÛÚ ¼Ü¹¹Éè¼Æ·½·¨°¸ÀýÓëʵ¼ù
ǶÈëʽÈí¼þ¼Ü¹¹Éè¼Æ¡ª¸ß¼¶Êµ¼ù