Prezante Manadjè API InterSystems (+ webinar)

Nou fèk pibliye InterSystems API Manager (IAM), yon nouvo eleman nan InterSystems IRIS Data Platform ki bay vizibilite, kontwòl, ak jesyon trafik API entènèt atravè enfrastrikti IT la.

Nan atik sa a, mwen pral montre w kouman pou w mete kanpe IAM epi montre kèk nan anpil kapasite ki disponib pou ou ak IAM. Manadjè API InterSystems pèmèt ou:

  • Siveye API a, konprann ki moun ki sèvi ak API a, ki API ki pi popilè, ak kiyès ki bezwen amelyorasyon.
  • Kontwole ki moun ki sèvi ak API a epi limite itilizasyon API soti nan restriksyon aksè senp ak restriksyon ki baze sou demann - ou gen kontwòl koutim epi ou ka byen vit reponn a chanje modèl konsomasyon API.
  • Sekirize API lè l sèvi avèk mekanis sekirite santralize tankou OAuth2.0, LDAP oswa Key Token Authentication.
  • Fè li pi fasil pou devlopè twazyèm pati yo epi ba yo yon eksperyans API siperyè lè yo louvri yon pòtal devlopè devwe.
  • Echèl API a epi asire latansi repons minimòm.

Jesyon API esansyèl pou tranzisyon nan SOA oswa achitekti mikwosèvis, senplifye entegrasyon ant (mikwo)sèvis endividyèl yo, fè yo disponib pou tout konsomatè ekstèn ak entèn yo. Kòm yon rezilta, nouvo API vin pi fasil pou kreye, kenbe ak konsome.

Si w deja itilize InterSystems IRIS, ou ka ajoute opsyon IAM nan lisans ou. Opsyon IAM a gratis pou kliyan InterSystems IRIS, men ou dwe mande InterSystems yon nouvo kle lisans pou kòmanse itilize IAM.

Si w poko itilize InterSystems IRIS epi w ap planifye pou eseye InterSystems API Manager, tanpri kontakte InterSystems.

Kòmanse ak Enstalasyon

Kliyan InterSystems ka telechaje distribisyon IAM sou sit entènèt la WRC seksyon "Distribisyon lojisyèl" epi kouri kòm yon veso Docker. Kondisyon sistèm minimòm:

Okòmansman, ou bezwen telechaje imaj Docker la (Enpòtan! Achiv ki gen WRC a se pa yon imaj Docker, ou bezwen depale li, gen yon imaj Docker andedan):

docker load -i iam_image.tar

Kòmand sa a pral fè imaj IAM la disponib pou pita itilize sou sèvè w la. IAM kouri kòm yon veso separe, kidonk, ou ka echèl li poukont li de InterSystems IRIS. Kouri IAM mande aksè a InterSystems IRIS pou telechaje yon lisans.

Mete kanpe InterSystems IRIS:

  • Pèmèt aplikasyon entènèt la /api/IAM
  • Pèmèt itilizatè IAM
  • Chanje modpas itilizatè IAM

Koulye a, ann kòmanse veso IAM la. Nan achiv la ou pral jwenn scripts iam-setup pou Windows ak Unix (ak Mac). Scripts sa yo pral ede w fikse varyab anviwònman yo kòrèkteman, sa ki pèmèt veso IAM a etabli yon koneksyon ak InterSystems IRIS. Isit la se yon egzanp script la ap kouri sou Mac:

source ./iam-setup.sh 
Welcome to the InterSystems IRIS and InterSystems API Manager (IAM) setup script.
This script sets the ISC_IRIS_URL environment variable that is used by the IAM container to get the IAM license key from InterSystems IRIS.
Enter the full image repository, name and tag for your IAM docker image: intersystems/iam:0.34-1-1
Enter the IP address for your InterSystems IRIS instance. The IP address has to be accessible from within the IAM container, therefore, do not use "localhost" or "127.0.0.1" if IRIS is running on your local machine. Instead use the public IP address of your local machine. If IRIS is running in a container, use the public IP address of the host environment, not the IP address of the IRIS container. xxx.xxx.xxx.xxx               
Enter the web server port for your InterSystems IRIS instance: 52773
Enter the password for the IAM user for your InterSystems IRIS instance: 
Re-enter your password: 
Your inputs are:
Full image repository, name and tag for your IAM docker image: intersystems/iam:0.34-1-1
IP address for your InterSystems IRIS instance: xxx.xxx.xxx.xxx
Web server port for your InterSystems IRIS instance: 52773
Would you like to continue with these inputs (y/n)? y
Getting IAM license using your inputs...
Successfully got IAM license!
The ISC_IRIS_URL environment variable was set to: http://IAM:****************@xxx.xxx.xxx.xxx:52773/api/iam/license
WARNING: The environment variable is set for this shell only!
To start the services, run the following command in the top level directory: docker-compose up -d
To stop the services, run the following command in the top level directory: docker-compose down
URL for the IAM Manager portal: http://localhost:8002

Kòm ou ka wè, non imaj konplè a, adrès IP, pò InterSystems IRIS ak modpas pou itilizatè IAM a se tout sa ou bezwen pou kòmanse.

Olye pou yo kouri yon script, ou ka mete varyab anviwònman manyèlman:

ISC_IAM_IMAGE=intersystems/iam:0.34-1-1
ISC_IRIS_URL=http://IAM:<PASS>@<IP>:<PORT>/api/iam/license

Lanse

Koulye a, ann lanse IAM nan kouri lòd la:

docker-compose up -d

Kòmand sa a òganize kontenè IAM yo epi asire ke tout bagay ap mache kòrèkteman. Yo tcheke estati veso yo lè l sèvi avèk kòmandman an:

docker ps

Louvri koòdone admin nan navigatè w la localhost:8002.

Prezante Manadjè API InterSystems (+ webinar)

Li vid pou kounye a paske li se yon ne konplètman nouvo. Ann chanje sa. IAM sipòte konsèp espas travay pou divize API yo an modil ak/oswa kòmandman. Ale nan espas travay "default" ke nou pral itilize pou eksperyans nou yo.

Prezante Manadjè API InterSystems (+ webinar)

Nimewo a nan demann pou espas travay sa a se toujou zewo, men w ap jwenn yon lide sou konsèp debaz IAM yo nan meni ki sou bò gòch la. De premye eleman yo: Sèvis ak Wout yo se pi enpòtan an:

  • Sèvis se API a ke nou vle bay aksè a konsomatè yo. Kidonk, API REST nan InterSystems IRIS se yon Sèvis, menm jan se, pa egzanp, API Google si ou vle sèvi ak li.
  • Wout la deside nan ki Sèvis demann k ap rantre yo ta dwe voye. Chak Wout gen yon seri kondisyon espesifik, epi si yo satisfè, yo voye demann lan bay Sèvis ki apwopriye a. Pou egzanp, yon Route ka matche ak IP, domèn emèt, metòd HTTP, pati nan yon URI, oswa yon konbinezon de egzanp sa yo.

Lapòs

Ann kreye yon Sèvis InterSystems IRIS, ak valè sa yo:

Jaden
Valè
Deskripsyon

File
Iris
Non sèvis

lame
IP
InterSystems IRIS sèvè lame oswa ip


52773
InterSystems IRIS sèvè pò entènèt

chemen
/api/atelier
Chemen rasin

pwotokòl
http
Pwotokòl

Kite valè ki rete yo kòm default. Klike sou bouton an Create epi ekri ID Sèvis ki te kreye a.

Route

Koulye a, ann kreye yon wout:

Jaden
Valè
Deskripsyon

chemen
/api/atelier
Chemen rasin

pwotokòl
http
Pwotokòl

sèvis.id
gid soti nan 3
Sèvis (ID nan etap anvan)

Kite valè ki rete yo kòm default. Klike sou bouton an Create epi ekri ID Wout kreye a. Pa default, IAM koute demann fèk ap rantre sou pò 8000. Koulye a, demann yo voye bay http://localhost:8000 epi kòmanse avèk /api/atelier yo redireksyon sou InterSystems IRIS.

Tès

Ann eseye kreye yon demann nan yon kliyan REST (mwen itilize post-man).

Prezante Manadjè API InterSystems (+ webinar)

Ann voye yon demann GET bay http://localhost:8000/api/atelier/ (pa bliye / nan fen a) epi resevwa yon repons nan men InterSystems IRIS. Chak demann ale nan IAM ki kolekte paramèt:

  • Kòd estati HTTP.
  • Reta.
  • Siveyans (si configuré).

Mwen te fè kèk demann plis (ki gen ladan de demann nan pwen final ki pa egziste tankou /api/atelier/est/), rezilta yo vizib imedyatman nan tablodbò a:

Prezante Manadjè API InterSystems (+ webinar)

Travay ak grefon

Kounye a ke nou gen yon Route configuré, nou ka jere API nou an. Nou ka ajoute karakteristik ki pral konplete sèvis nou an.

Fason ki pi komen pou chanje konpòtman yon API se ajoute yon plugin. Plugins izole fonksyonalite endividyèl yo epi yo ka konekte ak IAM swa globalman oswa sèlman nan antite endividyèl, tankou yon Itilizatè (gwoup itilizatè), Sèvis oswa Route. Nou pral kòmanse pa ajoute plugin Rate Limiting la sou wout la. Pou etabli yon koneksyon ant Plugin a ak wout la, nou bezwen yon idantifyan inik (ID) nan wout la.

Limite kantite demann yo

Klike sou Plugins nan meni bò gòch la. Ou ka wè tout grefon aktif yo sou ekran sa a, men kòm sèvè IAM sa a nouvo, pa gen okenn grefon aktif ankò. Se konsa, kontinye nan pwochen etap la pa klike "Nouvo Plugin".

Plugin nou bezwen an se nan kategori "Kontwòl trafik" epi li rele "Limite to". Chwazi li. Gen kèk paramèt ou ka mete isit la, men nou sèlman pran swen de jaden:

Jaden
Valè
Deskripsyon

route_id
ID
ID wout

konfigirasyon.minit
5
Kantite demann pou chak minit

Se tout. Plugin a configuré ak aktif. Remake byen ke nou ka chwazi diferan entèval tan, tankou yon minit, yon èdtan oswa yon jou. Anviwònman yo ka konbine (pa egzanp, 1000 demann pou chak èdtan ak an menm tan an 100 demann pou chak minit). Mwen te chwazi minit paske li fasil pou tcheke fonksyonalite Plugin la.

Si w voye menm demann lan ankò nan Postman, w ap wè repons lan retounen ak 2 tèt adisyonèl:

  • XRateLimit-Limit-minit: 5
  • XRateLimit-Rete-minit: 4

Sa a di kliyan an ke li ka fè jiska 5 demann pou chak minit epi li ka fè 4 demann plis nan plas tan aktyèl la.

Prezante Manadjè API InterSystems (+ webinar)

Si w fè menm demann lan plizyè fwa, w ap fini evantyèlman soti nan kota ki disponib epi olye w ap resevwa yon kòd estati HTTP 429 ak kò repons sa a:

Prezante Manadjè API InterSystems (+ webinar)

Rete tann yon minit epi w ap kapab soumèt demann ankò.

Sa a se yon mekanis pratik ki pèmèt ou:

  • Pwoteje backend la kont monte chaj.
  • Di kliyan konbyen demann yo ka fè.
  • Monetize API a.

Ou ka mete valè pou diferan entèval tan e konsa lis trafik API sou yon sèten peryòd tan. Ann di ou pèmèt 600 demann pou chak èdtan sou yon wout patikilye. Nan mwayèn, gen 10 demann pou chak minit. Men, pa gen anyen ki anpeche kliyan an ranpli tout 600 demann nan premye minit nan èdtan an. Petèt sa a se sa ou bezwen. Ou ka vle reyalize yon chaj plis menm sou kou a nan yon èdtan. Pa mete valè jaden an config.minute Yon valè 20 asire ke itilizatè ou yo pa fè plis pase 20 demann pou chak minit ak 600 demann pou chak èdtan. Sa a pèmèt pou ti Spikes sou yon entèval yon minit konpare ak yon koule totalman mwayèn nan 10 demann pou chak minit, men itilizatè yo pa ka itilize kota èdtan an pou yon minit. Koulye a, yo pral bezwen omwen 30 minit pou itilize tout demann yo. Kliyan yo pral resevwa tèt adisyonèl pou chak entèval tan espesifye, pou egzanp:

HTTP Header
Valè

X-RateLimit-Limit-èdtan
600

X-RateLimit-Rès-èdtan
595

X-RateLimit-Limit-minit
20

X-RateLimit-Rès-minit
16

Natirèlman, gen plizyè fason diferan pou konfigirasyon limit rechèch depann sou sa ou vle reyalize.

Jwenn

Mwen pral fini isit la, mwen panse ke gen ase materyèl pou premye atik la sou InterSystems API Manager. Nou itilize sèlman youn nan plis pase 40 grefon. Gen anpil lòt bagay enteresan ou ka fè ak IAM:

  • Ajoute yon mekanis otantifikasyon santral pou tout API ou yo.
  • Echèl chaj la lè l sèvi avèk yon balans chaj nan plizyè Sèvis.
  • Ajoute nouvo fonksyonalite ak korije ensèk nan yon odyans tès anvan yon aktyalizasyon konplè.
  • Bay devlopè entèn ak ekstèn yon pòtal entènèt dedye ki dokimante tout API yo.
  • Cache demann pou diminye tan repons lan epi redwi chaj la sou backend sistèm lan.

Referans

Vebinèr

Nou envite w nan webinar "Jesyon API ak Jesyon API InterSystems", ki pral pran plas 21 Novanm nan 10:00 lè Moskou (GMT+3).
InterSystems API Manager (IAM) se yon nouvo eleman nan InterSystems IRIS Data Platform ki bay siveyans, kontwòl ak jesyon trafik pou ale/soti nan API entènèt nan enfrastrikti IT la. Nan webinar a nou pral montre kapasite kle InterSystems API Management:

  • Zouti siveyans trafik API.
  • Kontwòl trafik API, ki gen ladan kontwòl bandwidth, limite kantite apèl API, kenbe lis adrès IP ki pèmèt ak refize, elatriye.
  • Zouti konfigirasyon sekirite API.
  • Pòtal Developer pou pibliye dokiman API entèaktif.
  • Single pwen aksè nan API a.

Webinar a fèt pou achitèk, devlopè ak administratè sistèm yo.

Enskripsyon obligatwa!

Sous: www.habr.com

Add nouvo kòmantè