1. 程式人生 > >Postman:Postman簡介、安裝、入門使用方法詳細攻略

Postman:Postman簡介、安裝、入門使用方法詳細攻略

Postman簡介

     開發API後,用於API測試的工具。在我們平時開發中,特別是需要與介面打交道時,無論是寫介面還是用介面,拿到介面後肯定都得提前測試一下。在開發APP介面的過程中,一般介面寫完之後,後端開發都會模擬呼叫一下請求。在用Postman之前,對於一般的get請求我基本都會用瀏覽器來簡單模擬。而對於post請求,我一般習慣寫程式碼來呼叫。可以用Java來模擬,當然用Python會更簡潔。但是還有有很多弊端,不便於管理、維護困難等。Postman具有每個API開發人員的功能:請求構建,測試和預請求指令碼,變數,環境和請求描述,旨在無縫地一起工作。

      這樣的話就非常需要有一個比較給力的Http請求模擬工具,現在流行的這種工具也挺多的,像火狐瀏覽器外掛-RESTClient,Chrome瀏覽器外掛-Postman等等。這裡主要介紹一下,一款模擬請求的利器Postman。

     Postman是一種網頁除錯與傳送網頁http請求的chrome外掛。我們可以用來很方便的模擬get或者post或者其他方式的請求來除錯介面。在Postman中,請求可以儲存,也就類似於檔案。而Collection類似資料夾,可以把同一個專案的請求放在一個Collection裡方便管理和分享,Collection裡面也可以再建資料夾。

Postman安裝

1、此方法需要FQ,在安裝時,最好是通過chrome瀏覽器開啟chrome網上應用店直接新增到chrome外掛中。如果是直接從網上先把postman下載好很可能按不到chrome上去。

2、

Postman入門

http://localhost:5000/mine

{
  "index": 2,
  "message": "New Block Forged",
  "previous_hash": "bcf967686847793897aab280b106ea30017c439aaeec21c9c7bd95472158268f",
  "proof": 12383,
  "transactions": [
    {
      "amount": 1,
      "recipient": "b5ae874dc9324a128f4889f89e340112",
      "sender": "0"
    }
  ]
}

http://localhost:5000/transactions/new

{
 "sender": "b5ae874dc9324a128f4889f89e340112",
 "recipient": "someone else's address",
 "amount": 5
}

{
  "message": "Transaction will be added to Block 3"
}

http://localhost:5000/chain

{
  "chain": [
    {
      "index": 1,
      "previous_hash": "1",
      "proof": 100,
      "timestamp": 1523154040.807251,
      "transactions": []
    },
    {
      "index": 2,
      "previous_hash": "bcf967686847793897aab280b106ea30017c439aaeec21c9c7bd95472158268f",
      "proof": 12383,
      "timestamp": 1523154095.569124,
      "transactions": [
        {
          "amount": 1,
          "recipient": "b5ae874dc9324a128f4889f89e340112",
          "sender": "0"
        }
      ]
    }
  ],
  "length": 2
}

pipenv run python blockchain.py
pipenv run python blockchain.py -p 5001

{
	"nodes":["http://127.0.0.1:5001"]
}

{
  "message": "New nodes have been added",
  "total_nodes": [
    "127.0.0.1:5001"
  ]
}