Skip to content

Latest commit

 

History

History
191 lines (101 loc) · 7.82 KB

File metadata and controls

191 lines (101 loc) · 7.82 KB

Learn postman

  • ❤️ You can export collection via CLI in postman as described in this comment - Click here

  • TODO: Learn tests with postman -

image

  • Open link in browser
  • We can mark collections as starred so that they appear on the top like that -

image

  • We can use params ❤️❤️ in postman with a beautiful syntax like that:

image

  • Delete workspace (#remove workspace)

image

image

  • TODO: Learn how teams work in postman

image

  • Choosing between collection variables vs. environment variables

NOTE: Environment variables always override collection variables.

image

  • Important: Postman never read values form "Initial value" column ever.

image

  • Inheriting authorization from authorization defined in collection settings

image

Beware Beware Beware that you must remove "Inherit Authorization" from the signin/login requests as shown in below screenshot otherwise your' backend may intercept those requests badly. (WARNIN: In slasher it actually does).

image

  • Setting variable at collection level:
var jsonData = pm.response.json();

// 1. setting in currently active environment (MOST COMMONLY NEEDED, Date: 28 May, 2023)
pm.environment.set("TOKEN1", jsonData.token);

// 2. setting collection variable
pm.collectionVariables.set("TOKEN1", jsonData.token);

// 3. setting globally
pm.globals.set("TOKEN1", jsonData.token);

image

  • Thats how you set collection specific variables:

image

image

  • Thats how you export a postman collection:

image

  • There are three types of variables-

image

  • To use a environment variable, make sure you have an active environment:

image

  • Realistic Example of setting and using a global variable (global environment variable):

image

image

image

  • Thats how you set a global variable with postman tests:

image

  • Course video:

  • Socket.io Server Requests

    Source: Official Postman Article - Click here

    image

    image

    • You can choose client version now:

    image

    • Set url of socket now (connects automatically to: localhost:PORT/socket.io):

    image

    • You can set authorization header with socket like that (even though browsers don't allow setting headers for socket connections yet ~Eric Slasher Project Notes):

    image

    • Listening to event and sending event (see next screenshot as well):

    image

    image

  • How do we get the return value (Acknowledgement) from the event as we can see the return value of the event handler in the code:

    image

  • You can write documentation for a postman requets like that:

image

  • In a request payload you can now write comments with // and /* */ format by adding that pre-script code

Source Stackoverflow Answer: Click here

// Strip JSON Comments
if (pm?.request?.body?.options?.raw?.language === 'json') {
    const rawData = pm.request.body.toString();
    const strippedData = rawData.replace(
        /\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,
        (m, g) => g ? "" : m
    );
    pm.request.body.update(JSON.stringify(JSON.parse(strippedData)));
}

// To set Content-Type again (see the original stackoverflow answer's comment section):
// pm.request.upsertHeader({key: 'Content-Type', value: 'application/json'});
  • Also you can make use explicit comment section to make notes as well:

image

  • Hidden Headers?

image

  • Thats how you can use param variables (actually called path variables in postman)

    image

  • Set authorization "bearer token" header easily

image

image

  • How to send file in http request

Click here

image

In slasher:

image

  • We can fetch an image in postman as well:

image