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

عملاء الـ API

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

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

نظرة عامة

الموضوعات

  • Postman
  • curl
  • مجموعات الـ API (Collections)
  • متغيرات البيئة

تعلّم أولًا

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

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

  1. Organize Postman collections with environments and variables.
  2. Chain requests (capture an ID or token from one response for the next).
  3. Write curl commands for any endpoint, including headers and JSON bodies.
  4. Call an external HTTP API from Spring with RestClient.

الدروس

  1. 01مجموعات Postman والبيئات
  2. 02السكربتات والطلبات المتسلسلة
  3. 03إتقان curl
  4. 04استدعاء واجهات API أخرى من Spring
  5. 05عرض عملي: مجموعة Postman متسلسلة مع بيئات

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

Lab

JNR-022-LAB1 · Shop collection

Outcomes: 1–4 · Time: ~1.5 h Create a shared Postman collection for Shop API with local and deployed environments and chained requests (create, read, update, delete). In the application, fetch exchange rates from an external API through RestClient, with connect and read timeouts configured.

Acceptance: the collection runs end-to-end; timeout configured.

Exercises (assessment: lab check)

IDOutcomeTask
JNR-022-EX011Create local and deployed environments with baseUrl and use {{baseUrl}} in every request.
JNR-022-EX022Chain: create a product, store its ID, then fetch it with the stored ID.
JNR-022-EX032Add tests to the chain that check status codes and that the returned id is present.
JNR-022-EX043Write curl commands for list, create (JSON body), update, and delete on products.
JNR-022-EX054Call a public JSON API with RestClient and map the response to a record.
JNR-022-EX064Configure timeouts and show what happens when the remote is slow or unreachable.
أظهر الحلول
  • EX01 Environment variables baseUrl; requests use {{baseUrl}}/products; no host strings remain.
  • EX02 pm.environment.set("productId", pm.response.json().id), then GET {{baseUrl}}/products/{{productId}}.
  • EX03 pm.test("201", () => pm.response.to.have.status(201)); and check json.id.
  • EX04 e.g. curl -i -X PUT localhost:8080/products/1 -H 'Content-Type: application/json' -d '{...}'; curl -i -X DELETE localhost:8080/products/1.
  • EX05 client.get().uri(...).retrieve().body(MyRecord.class).
  • EX06 Build the client with request factory settings for connect and read timeouts (verify the exact API for your Spring version); catch the exception and return a clear error or fallback.

Outcome 1 is also checked by quiz Q01 and the lab's two environments.

الاختبار

Outcomes: O1 collections and environments · O2 chaining · O3 curl · O4 RestClient.

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

  1. 1A Postman environment holds:O1
  2. 2Why not hard-code hosts and tokens in a shared collection?O1
  3. 3How does request 2 use an ID from request 1?O2
  4. 4What do Postman tests add?O2
  5. 5curl -i does what?O3
  6. 6To send JSON with curl you set:O3
  7. 7Which sets the method?O3
  8. 8RestClient is used to:O4
  9. 9A client without timeouts risks:O4
  10. 10After .retrieve(), .body(Rates.class) does:O4

الجزء العملي

Six exercises JNR-022-EX01 to EX06 plus the collection lab. Pass: at least five exercises and a lab where the collection runs end to end and the RestClient has timeouts.

أخطاء شائعة

Hard-coded hosts and tokens in collections; HTTP clients without timeouts.

التقييم

Lab check.

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

API testing (JNR-046) and resilience (MID-033).

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