<img height="1" width="1" style="display:none;" alt="" src="https://ct.pinterest.com/v3/?event=init&amp;tid=2612994575055&amp;pd[em]=<hashed_email_address>&amp;noscript=1">
Skip to content
    AdminOct 2, 2023 6:55:19 PM< 1 min read

    Swagger GET Method in Laravel

    After successfully implementing the Swagger Post Method in Laravel, it's time to explore the Swagger GET Method in Laravel.

    /**
         * @OA\Get(
         *      path="/get-user/{id}",
         *      operationId="getUser",
         *      tags={"User"},
         *      summary="Get User",
         *      description="Get User",
         *      @OA\Parameter(
         *      name="id",
         *      in="path",
         *      required=true,
         *      description= "user id",
         *      example="10",
         *      @OA\Schema(
         *           type="integer"
         *      )
         *      ),
         *       @OA\Response(
         *      response=200,
         *      description="Success response",
         *      @OA\JsonContent(
         *      @OA\Property(property="status", type="number", example="200"),
         *      @OA\Property(property="user", type="string", example="{'full_name':'Chetan','email_id':'chetan1234@gmail.com','created_at':'2022-05-27T07:16:57.000000Z','updated_at':'2022-05-27T07:16:57.000000Z'}"),
         *        )
         *     ),
         *        @OA\Response(
         *      response=400,
         *      description="Bad Request",
         *      @OA\JsonContent(
         *      @OA\Property(property="status", type="number", example="400"),
         *      @OA\Property(property="message", type="string", example="Error in processing request")
         *        )
         *     )
         * )
         *      
         * )
         */
    
        public function getUser($id)
        {
        	try {
    	    	$user = User::where('id', $id)->get();
    
    	    	if($user){
    	    		return response()->json(['status' => 200, 'user' => $user], 200);
    	    	}
        	}catch (\Exception $e) {
                return response()->json(['status' => 400, 'message' => 'Error in processing request'], 400);
            }
        }

    Now, run php artisan l5-swagger:generate and check api at https://mywebsite.com/api/documentation.

    Read laravel swagger documentation here.

    COMMENTS

    RELATED ARTICLES