He aha ka Restful Web Services

Introduction

Ma kā mākou ʻatikala mua ua kūkākūkā mākou i ka mea he API. Aia nā ʻano kelepona API like ʻole e laʻa me Simple Object Access Protocol (SOAP), Remote Procedure Call (RPC) a me Representational State Transfer (REST). Loaʻa i kēia mau kelepona API ke kumu like ʻo ia hoʻi e hoʻoili i ka ʻikepili ma waena o ʻelua a ʻoi aku paha nā ʻōnaehana. Ma kēia ʻatikala e ʻimi wale mākou i ka Restful Web Services.

He aha ka REST

E like me ka mea i hōʻike mua ʻia, kū ʻo REST no Representational State Transfer. He ala maʻalahi ia o ka hoʻouna ʻana a me ka loaʻa ʻana o ka ʻikepili ma waena o ka mea kūʻai aku a me ke kikowaena. ʻAʻole pono ia i kekahi polokalamu a i ʻole nā ​​kūlana e hoʻoili i ka ʻikepili. Loaʻa iā ia kahi ʻōnaehana i koho mua ʻia e hana i ke kelepona API. Pono nā mea hoʻomohala e hoʻohana i ke ala i koho mua ʻia a hāʻawi i kā lākou ʻikepili e like me ka uku JSON.

Nā lawelawe pūnaewele hoʻomaha

Nā ʻano o nā lawelawe pūnaewele hoʻomaha

Loaʻa i kahi lawelawe pūnaewele RESTful nā ʻeono kaohi/ʻano:

  1. Mea kūʻai aku-kauwaʻa: He mea koʻikoʻi loa ia o nā REST API. A REST API e hahai ana i ka hale kūʻai-server a pono e kaʻawale kēia mau mea ʻelua. 'O ia ho'i, 'a'ole hiki i ke kikowaena a me ka mea kū'ai ke kikowaena like. Inā like ia, e loaʻa iā ʻoe ka hewa CORS.
  2. Mokuʻāina ʻole: Ma REST, mālama ʻia nā kelepona a pau ma ke ʻano he kelepona hou a ʻaʻole e hāʻawi ka mokuʻāina kelepona i kekahi pono i ke kelepona hou. No laila i kēlā me kēia kelepona, pono e mālama i ka hōʻoia pono a me nā ʻike ʻē aʻe.
  3. Kālena: Hoʻoikaika ka API REST i ka polokalamu kele pūnaewele a me ke kaʻina hoʻokae server e hoʻonui i kona wikiwiki.
  4. ʻAnoʻano like ʻole: ʻO ka pilina ma waena o ka mea kūʻai aku a me ka Server e mau ana i nā ʻano like ʻole, no laila ʻaʻole pili nā loli i kēlā me kēia ʻaoʻao i ka hana API. Kōkua kēia i ka hoʻomohala ʻana i ka ʻōnaehana kūʻai kūʻokoʻa.
  5. Pūnaehana Layered: ʻAe ʻo REST i ka hoʻohana ʻana i ka hoʻolālā papa ma ka ʻaoʻao kikowaena ʻo ia hoʻi hiki iā ʻoe ke loaʻa ka ʻikepili ma nā kikowaena like ʻole, ka hōʻoia ʻana ma kahi kikowaena ʻokoʻa aʻo ka API ma kahi kikowaena ʻokoʻa. ʻAʻole ʻike ka mea kūʻai aku e loaʻa ana ka ʻikepili mai kahi kikowaena.
  6. Code ma ke koi: He hiʻohiʻona koho o REST API kahi e hiki ai i ke kikowaena ke hoʻouna i nā code executable i ka mea kūʻai aku hiki ke holo pololei i ka wā holo.

Nā Kaʻina i loko o ka Restful Web Services

Ke hoʻohana nei i nā lawelawe pūnaewele Restful, hiki iā mākou ke hana i kēia mau hana maʻamau ʻehā:

  1. GET: Hoʻohana ʻia kēia ʻano no ka loaʻa ʻana o kahi papa inoa o ka ʻikepili mai ke kikowaena.
  2. POST: Hoʻohana ʻia kēia ʻano no ka hoʻouna ʻana/hana i kahi moʻolelo hou ma ka kikowaena.
  3. PUT: Hoʻohana ʻia kēia ʻano hana e hōʻano hou i kahi moʻolelo o ke kikowaena.
  4. DELETE: Hoʻohana ʻia kēia ʻano hana no ka holoi ʻana i kahi moʻolelo ma ka ʻaoʻao kikowaena.

'Ōlelo Aʻo: ʻO ke kāhea wale ʻana i ke ʻano o luna ʻaʻole ia e hōʻoiaʻiʻo e hana ʻia nā hana a hiki i ka hoʻokō ʻia ʻana o kēia mau hana ma ka ʻaoʻao kikowaena pū kekahi.

ʻO nā pono o nā lawelawe pūnaewele hoʻomaha

Aia ma lalo iho nā pōmaikaʻi nui o kahi RESTful API:

  • He maʻalahi a maʻalahi lākou e hoʻokō
  • Kākoʻo ia i ka nui o nā ʻano palapala ʻikepili e like me JSON, XML, YAML, etc.
  • ʻOi aku ka wikiwiki a hāʻawi i ka hana ʻoi aku ka maikaʻi

Nā pōʻino o nā lawelawe pūnaewele hoʻomaha

ʻOiai hāʻawi nā lawelawe REST i nā pōmaikaʻi he nui, ua hāʻawi ʻia nā hemahema:

  • No ka hoʻokō ʻana i ka nīnau pili mokuʻāina pono ʻia nā poʻo REST he hana paʻakikī
  • ʻAʻole hiki ke hoʻohana ʻia nā hana PUT a me DELETE ma o nā pā ahi a i ʻole kekahi mau polokalamu kele pūnaewele.

Waiho i ka manaʻo hoʻopuka

Ke hoʻohana nei kēia pūnaewele i ka Akismet e ho'ēmi i ka spam. E aʻo pehea e hanaʻia ai kāuʻikeʻikepili.