function plugin_name_route_api( \WP_REST_Request $req ) {
$token = get_option('bearer_token');
$headers = $req->get_headers();
$auth_token = $headers['authorization'][0];
if ( $token != $auth_token ) {
return new WP_Error( '401', esc_html__( 'Not Authorized', 'text_domain' ), array( 'status' => 401 ) );
}
return json_encode(["message" => "Authorized"]);
}