HOW TO GENERATE AN API DOCUMENTATION

Mar 27, 2022 Copy Link

من الحاجات الجميلة في Laravel إنه في packages كتير هتساعدك في شغلك و هنا في المقالة دي هتكلم عن إزاي تعمل documentation لل APIs بتاعتك 📖

 

طيب إحنا بنحتاج زي دي في إيه؟ 🤔

 

هقولك إننا بنحتاج حاجة زي دي لما يكون في Mobile Team شغال معانا فلازم هنا هنحتاج ال documentation عشان نعرفهم تفاصيل كل Endpoint 🔭

 

أول package معانا هتساعدك في الموضوع دا هي L5-Swagger 🗃

 

الباكدج دي جميلة جداً بس محتاجة إنك تكتب كل حاجة بنفسك, بمعني إنك لما تحب تعمل documentation لازم تكتب ال meta-data فوق كل function بتوضح فيها شوية معلومات زي الكود دا 👇

 

/**
 * @OA\Put(
 *     path="/users/{user}",
 *     summary="Update a user by their ID",
 *     @OA\Parameter(
 *         description="Updates the details of an existing user identified by the given ID.",
 *         in="path",
 *         name="user",
 *         required=true,
 *         @OA\Schema(type="string"),
 *         @OA\Examples(example="int", value="1", summary="A sample user ID"),
 *     ),
 *     @OA\Response(
 *         response=200,
 *         description="OK"
 *     )
 * )
 */
public function update(User $user)
{
    // Perform the update operation here...
}

 

و من خلال الكود اللي فوق دا هيبان في ال documentation الحاجات اللي إنت كتبتها زي ال path و وصف لل API و كمان بتوصف شكل ال response بتاعك 🧐

 

و مع package زي دي كل ما تضيف أو تعدل أو تحذف route لازم تعدل ال documentation بنفسك, بس إنت ك developer ممكن متحبش حاجة زي دي لإنك بتكون مُهتم بالكود بس و عشان كدا هقولك علي باكدج تانية و هي Swagger 🗃

 

الباكدج دي جميلة جداً وسهلة الإستخدام وبُمجرد إنك تعملها install وترح لل request-docs/ هتلاقي documentation مُحترم مستنيك 🚀

 

و بكدا أكون خلصت و أتمني تكون إستفدت ✔

Share via

Mahmoud Ramadan

Mahmoud Ramadan

Mahmoud is the creator of Digging Code and a contributor to Laravel since 2020.

Newly published

  • How to Enable Relationship Autoloading in Versions Before v12.8

    How to Enable Relationship Autoloading in Versions Before v12.8

    PREMIUM

  • Get your environment ready to welcome Laravel v12

    Get your environment ready to welcome Laravel v12

    PREMIUM

  • How to generate Arabic PDF using TCPDF

    How to generate Arabic PDF using TCPDF

    FREE