Menene Sabis na Yanar Sadarwa

Gabatarwa

A labarinmu da ya gabata mun tattauna menene API. Akwai nau'ikan kiran API daban-daban misali Simple Object Access Protocol (SOAP), Kiran Hanyar Nesa (RPC) da Canja wurin Jiha Wakili (REST). Duk waɗannan kiran API suna da manufa iri ɗaya watau don canja wurin bayanai amintattu tsakanin tsarin biyu ko fiye. A cikin wannan labarin za mu bincika Sabis ɗin Gidan Yanar Gizo mai Huta kawai.

Menene REST

Kamar yadda aka fada a baya, REST yana nufin Canja wurin Jiha na Wakilai. Hanya ce mai sauƙi ta aikawa da karɓar bayanai tsakanin abokin ciniki da uwar garke. Baya buƙatar kowace software ko ƙa'idodi don canja wurin bayanai. Yana da ƙayyadaddun tsari don yin kiran API. Masu haɓakawa kawai suna buƙatar amfani da hanyar da aka riga aka ƙayyade kuma su ƙaddamar da bayanan su azaman jigilar JSON.

Sabis na Yanar Sadarwa

Halayen Sabis na Gidan Yanar Sadarwa

Sabis ɗin gidan yanar gizo mai RESTful yana da ƙuntatawa / halaye guda shida:

  1. Abokin Ciniki-Server: Abu ne mai mahimmanci na REST APIs. API ɗin REST yana biye da gine-ginen uwar garken abokin ciniki kuma waɗannan duka ya kamata su kasance daban. Yana nufin duka uwar garken da abokin ciniki ba za su iya zama sabar iri ɗaya ba. Idan ya kasance iri ɗaya, zaku sami kuskuren CORS.
  2. Mara kasa: A cikin REST, duk kiran ana ɗaukarsu azaman sabon kira kuma duk wata jiha ta baya ba zata ba da wani fa'ida ga sabon kiran ba. Don haka a lokacin kowane kira, ana buƙatar kiyaye duk ingantaccen tabbaci da sauran bayanan da suka dace.
  3. Cache: API ɗin REST yana ƙarfafa tsarin mai lilo da uwar garken caching don haɓaka saurin sarrafa shi.
  4. Interface Interface: Ma'amala tsakanin Abokin ciniki da uwar garken ya kasance iri ɗaya, don haka duk wani canje-canje a kowane bangare ba zai shafi ayyukan API ba. Wannan yana taimakawa wajen haɓaka tsarin Client da Server da kansa.
  5. Tsarin Layi: REST yana ba da damar yin amfani da tsari mai laushi a gefen uwar garken watau zaku iya samun bayanai akan sabar daban-daban, tantancewa akan sabar daban-daban yayin da API akan sabar daban-daban. Abokin ciniki ba zai taɓa sanin cewa yana samun bayanan daga wane uwar garken ba.
  6. Lambar akan Bukatar: Siffar zaɓi ce ta REST API inda uwar garken zata iya aikawa da lambar aiwatarwa ga abokin ciniki wanda zai iya aiki kai tsaye yayin lokacin gudu.

Hanyoyi a cikin Sabis na Gidan Yanar Sadarwa

Amfani da Sabis na Gidan Yanar Gizo, za mu iya yin waɗannan ainihin ayyuka guda huɗu:

  1. SAMU: Ana amfani da wannan hanyar don samun jerin bayanai daga uwar garken.
  2. POST: Ana amfani da wannan hanyar don aikawa / ƙirƙira sabon rikodin a cikin uwar garken.
  3. PUT: Ana amfani da wannan hanyar don sabunta rikodin uwar garken data kasance.
  4. SHAFE: Ana amfani da wannan hanyar don yin share rikodin a gefen uwar garke.

lura: Kiran hanyar da ke sama kawai baya bada garantin cewa za a gudanar da ayyukan har sai an aiwatar da waɗannan ayyuka a gefen uwar garken ma.

Fa'idodin Sabis na Gidan Yanar Sadarwa

Masu zuwa sune manyan fa'idodin API na RESTful:

  • Sun fi sauƙi da sauƙi don aiwatarwa
  • Yana goyan bayan mafi girman nau'ikan tsarin bayanai misali JSON, XML, YAML, da sauransu.
  • Yana da sauri kuma yana ba da kyakkyawan aiki

Lalacewar Sabis na Gidan Yanar Sadarwa

Kodayake sabis na REST yana ba da fa'idodi da yawa, duk da haka ya ba da lahani:

  • Don aiwatar da tambayar da ke da alaƙa da jiha ana buƙatar Shugabanni na REST wanda aiki ne mara nauyi
  • Ba a iya amfani da ayyukan PUT da DELETE ta hanyar wuta ko a wasu masu bincike.

Bar Tsokaci

Wannan shafin yana amfani da Akismet don rage spam. Koyi yadda aka sarrafa bayanan bayaninka.