انتقل إلى المحتوى
أمين أبوزيد
MID-035

بوابات API (API Gateways)

  • 6 درس
  • 2.5 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • التوجيه
  • التكامل مع المصادقة
  • مسؤوليات البوابة

تعلّم أولًا

2.5 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Describe gateway responsibilities: routing, TLS termination, authentication, rate limiting, request shaping.
  2. Configure Spring Cloud Gateway (or an equivalent) in front of Shop's services.
  3. Decide what belongs in the gateway vs in services, and avoid business logic at the edge.
  4. Explain the backend-for-frontend pattern.

الدروس

  1. 01لماذا بوابة
  2. 02التوجيه والمرشّحات
  3. 03المصادقة عند الحافة
  4. 04ما لا يجب وضعه في البوابة
  5. 05الواجهة الخلفية للواجهة الأمامية (Backend for Frontend)
  6. 06عرض عملي: نقطة دخول واحدة لأربع خدمات

المختبر والتمارين

Lab

MID-035-LAB1 · Shop gateway

Outcomes: 1–4 · Time: ~2.5 h Build a Spring Cloud Gateway (or an equivalent) as the single public entry point for catalog, orders, inventory, and payments. Validate JWTs at the edge, route by path, add a correlation id, and apply rate limits (MID-034). Remove published ports from the services so they are reachable only through the gateway on the Compose network, and keep token validation in services.

Acceptance: services are not reachable directly from outside; requests without a valid token get 401 at the gateway; a request with a forged identity header does not gain access.

Exercises (assessment: responsibility-placement exercise)

IDOutcomeTask
MID-035-EX011List five responsibilities of an API gateway with one sentence each.
MID-035-EX022Write the route configuration for catalog and orders with path predicates and prefix stripping.
MID-035-EX032Configure JWT validation so /api/products/** is public and everything else needs a token.
MID-035-EX043Responsibility placement: for 10 concerns (TLS, CORS, discount calculation, order ownership, rate limit, JWT signature check, response aggregation, request logging, retry of payment, feature flags per customer), decide gateway, service, or BFF.
MID-035-EX053A team wants to add stock-based pricing rules to the gateway. Write a short rejection with the better place.
MID-035-EX064Describe when Shop needs a BFF and sketch a mobile BFF response for the home screen.
أظهر الحلول
  • EX01 Routing, TLS termination, authentication, rate limiting, request shaping (headers, rewrites, correlation id); also CORS and logging.
  • EX02 Two routes with Path=/api/products/** to http://catalog:8080 and Path=/api/orders/** to http://orders:8080, filter StripPrefix=1.
  • EX03 Resource-server config with permitAll() for /api/products/** and authenticated() otherwise; configure issuer or JWK set URI.
  • EX04 Gateway: TLS, CORS, rate limit, JWT signature check, request logging. Service: discount calculation, order ownership, payment retry (with idempotency). BFF: response aggregation. Feature flags per customer: service (or a flag service), not the gateway.
  • EX05 Pricing is business logic; it would couple the gateway to inventory data and force gateway releases for every rule. Put it in catalog or a pricing component.
  • EX06 A BFF is justified when mobile needs aggregated, smaller payloads (featured products, cart count, order status) in one call, different from web; it calls catalog and orders and returns one tailored JSON.

Quiz Q09 and Q10 also cover outcome 4.

الاختبار

Outcomes: O1 responsibilities · O2 Spring Cloud Gateway · O3 gateway vs services · O4 BFF.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1Which is a typical gateway responsibility?O1
  2. 2A gateway gives clients:O1
  3. 3In Spring Cloud Gateway a predicate:O2
  4. 4StripPrefix=1 does what?O2
  5. 5Gateway filters should:O2
  6. 6"Customer may only see their own orders" belongs in:O3
  7. 7A gateway full of business rules becomes:O3
  8. 8Services should:O3
  9. 9A BFF is:O4
  10. 10The BFF differs from the gateway because it:O4

الجزء العملي

Six exercises MID-035-EX01 to EX06 including the responsibility-placement exercise, plus MID-035-LAB1. Pass: at least five exercises, correct placement of at least 8 of 10 concerns, and a lab where services are unreachable except through the gateway.

أخطاء شائعة

Gateway as a new monolith; services trusting any request with no token.

التقييم

Responsibility-placement exercise.

الصلة بالمسار الوظيفي

API management (ARC-025).

اكتب للبحث في المستويات والمراحل والوحدات والدروس.