讓我們可以去右上方直接選擇環境,又可以針對不同 collection 設置
let base_url;
switch (pm.environment.name){
case "local":
base_url = "http://localhost:3000/api/v1";
break;
case "uat":
base_url = "http://...:8111/api/v1";
break;
case "production":
base_url = "https://.../api/v1";
break;
}
pm.environment.set("base_url", base_url);
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Content-Type is application/json", function () {
pm.response.to.have.header("Content-Type", "application/json; charset=utf-8");
});
var jsonData = pm.response.json();
pm.environment.set("jwt", jsonData.token);
console.log(pm.environment.get('jwt'), jsonData.token)
private extractTokenFromHeader(request: Request): string | undefined {
const [type, token] = request.headers.authorization?.split(' ') ?? [];
return type === 'Bearer' ? token : undefined;
}