Postman etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Postman etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

13 Kasım 2022 Pazar

Postman Script

Örnek
Elimizde şöyle bir ön script olsun
function randomString() {
  ...
}
pm.collectionVariables.set('randomEmailPrefix', randomString());
Bir istek gönderelim
{
  "notificationEmail": "{{randomEmailPrefix}}@gmail.com",
  "customerType": "INDIVIDUAL"
}
Test metodlarını şöyle yaparız
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

pm.test("Customer has created successfully", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData).is.not.null;
    pm.expect(jsonData.id).is.not.null;
});

pm.test("Response has a valid json body", function () {
     pm.response.to.be.ok;
     pm.response.to.be.withBody;
     pm.response.to.be.json;
});

pm.collectionVariables.set("createdCustomerId",  pm.response.json().id);





20 Ekim 2022 Perşembe

Postman form-data POST - Form Gönderme

Giriş
Bir form gönderme içindir. Form içinde json alan gönderileceği gibi dosya da yüklenebilir.

Örnek - Dosya İçeren Form
Dosya yükleme için şöyle yaparız
import org.springframework.web.multipart.MultipartFile;
class User {
  public String userId;
  public String emailId;
  public MultipartFile profilePicImageFile;
}

@PostMapping("/upload/post")
public ResponseEntity<String> uploadProfilePic(@ModelAttribute User user) 
  throws Exception {
  
}
Örnek - Sadece Form
Şeklen şöyledir


@RestController
@RequestMapping("/")
@AllArgsConstructor
public class NotificationController {

  @GetMapping
  public String sendNotification(@RequestParam String message,
                                 @RequestParam NotificationType notificationType) {
    ...
  }
}

Örnek - Sadece Dosya
Dosya yükleme için şöyle yaparız

public List<InputFile> addFile(@RequestParam("files")MultipartFile[] files){
  return fileService.uploadFiles(files);
}