Reputation: 9503
Scenario: I'm trying to access an online calculator service from a Herokuapp.
Problem: I'm a Heroku & Postman neophyte.
Here's a given url to the service:
Base URL: https://calculator-frontend-challenge.herokuapp.com
This is supposed to be a POST; so I'm also given the following:
POST /calculations
...which creates a new calculation:
● Input: {}
● Output:
{
"id": "ecc7ab90-0a59-4168-b1e5-b5cf63edf9fd"
}
Ok... so far, so good.
So I got the id generated and retrieved.
Now I'm trying to attach some tokens per instruction:
via Postman, I tried to add the 'tokens':
And ID:
I'm lost here.
I need the correct POST format to get something back from herokuapp.
This doesn't require the use of Postman.
I'm merely using it as a development tool.
Attached is the assignment per request. I'm getting partial results but it's flaky.
Upvotes: 0
Views: 146
Reputation: 300
Upvotes: 1
Reputation: 4503
A POST
command has a body, they don't typically use query params. It looks like you are supposed to hit the root endpoint to get an id that you will use afterwards, this is your response on the first call. Then, you are supposed to use a POST
with an appropriate JSON body to build up your calculation.
POST https://calculator-frontend-challenge.herokuapp.com/calculations/ecc7ab90-0a59-4168-b1e5-b5cf63edf9fd/tokens
In your URLRequest, you can add your JSON body. Easiest way in Swift is to use a Codable
type and then use a JSONEncoder
to create the data.
struct TokenRequest: Codable {
let type: TokenType
let value: String
enum TokenType: String, Codable {
case operator
case number
}
}
let tokenRequest = TokenRequest(type: .number, value: "5")
var request = URLRequest(url: ...)
request.httpBody = try? JSONEncoder().encode(tokenRequest)
You should read up on RESTful services to get a better handle on the basics of how/why this works.
Upvotes: 0