Header Ads

[Postman Api test]The most effective method to test Programming interface for Invalid Login API in Postman.

Login API Test :

Postman is a famous and broadly utilized Programming interface improvement and testing API. It gives an easy to use interface that permits engineers to effectively make solicitations to APIs, dissect the reactions, and test different Programming interface endpoints and functionalities. Mailman upholds different HTTP demand strategies like GET, POST, PUT, Erase, and so forth, and permits clients to tweak headers, question boundaries, demand bodies, and verification instruments.



Here We will see how to test a login APi?

 


After testing we will get Like this Result:

So now we will see step by step:

1. How to create login Api in laravel?

Create a php database in phpmyadmin:

Model.php file:

   use HasFactory,Notifiable, HasApiTokens;
    public $table = "reg_user";
    protected $primaryKey = 'reg_id';
 
    protected $fillable = ['reg_name','reg_gender','reg_dob','reg_email',
'reg_password','reg_mobile_no','reg_address','reg_image','reg_path',
       
    ];


Code  for AuthController.php


    public function login(Request $request){
        $request->validate([
            'reg_email'=>'required',
            'reg_password'=>'required',
        ]);

       
        $user = registerModel::where('reg_email', $request->reg_email)->first();
        if($user && Hash::check($request->reg_password, $user->reg_password)){
            $token = $user->createToken($request->reg_email)->plainTextToken;
            return response([
                'token'=>$token,
                'user' => $user,
                'message' => 'Login Success',
                'status'=>'success'
            ], 200);
        }
        return response([
            'message' => 'The Provided Credentials are incorrect',
            'status'=>'failed'
        ], 401);
    }

 

$request->validate([
            'reg_email'=>'required',
            'reg_password'=>'required',
        ]); this we are using to validate the field. Below is the code to chekc the correct credential using database:


        $user = registerModel::where('reg_email', $request->reg_email)->first();
        if($user && Hash::check($request->reg_password, $user->reg_password)){
            $token = $user->createToken($request->reg_email)->plainTextToken;
            return response([
                'token'=>$token,
                'user' => $user,
                'message' => 'Login Success',
                'status'=>'success'
            ], 200);
        }
        return response([
            'message' => 'The Provided Credentials are incorrect',
            'status'=>'failed'
        ], 401);

Code for Api.php

Route::post('/auth/login', [AuthController::class, 'login']);

A few critical elements of API include:

Programming interface Documentation: API permits you to make point by point Programming interface documentation by bringing in Programming interface particulars or physically recording endpoints, boundaries, and reactions.

Programming interface Testing: API gives a strong testing system where you can make test scripts utilizing JavaScript. You can compose affirmations to approve the reaction information, check status codes, and confirm the general way of behaving of the Programming interface.

Assortment and Conditions: API allows you to sort out your Programming interface demands into assortments, making it simpler to oversee and execute various demands together. You can likewise establish various conditions to deal with factors and designs well defined for various conditions like turn of events, arranging, or creation.

Mock Servers: API permits you to make mock servers that reproduce Programming interface reactions, empowering frontend and backend groups to work autonomously during the advancement interaction.

Cooperation: API offers joint effort includes that work with collaboration and correspondence among colleagues. You can share assortments, work areas, and test results with associates, empowering consistent joint effort and information sharing.

Generally speaking, API works on the most common way of testing and communicating with APIs, making it a significant instrument for engineers, analyzers, and Programming interface customers.



For More Details :

Contact : info@infysky.com


No comments

Blinking TWO Led's with Arduino and Breadboard #03

Blinking TWO Led's with Arduino and Breadboard In this tutorial we will see how to turn on two Led's using Arduino Uno for beginn...

Powered by Blogger.