ufna / VaRest

REST API plugin for Unreal Engine 4 - we love restfull backend and JSON communications!
https://www.unrealengine.com/marketplace/en-US/product/varest-plugin
MIT License
1.07k stars 292 forks source link

How to insert API key to Set Header? Any Blueprint example? #383

Open ganbaaelmer opened 2 years ago

ganbaaelmer commented 2 years ago

How to insert API key to Set Header?

Any example on Blueprint?

image

image

How to use Set Header from Varest plugin?

I don’t know how to insert x-api-key to Varest?

Any Blueprint example?

chase03 commented 2 years ago

same question, need some help

chase03 commented 2 years ago

Same problem. How to Set Header correctly (Bearer "token" ) after login get token string?

shirkan164 commented 2 years ago

1st of all - I saw many of you rely on the "Call URL" - in most cases it's useless (not always)

Workflow: Mostly you want to add headers and everything, then you bind the Custom Event to On Request Complete (it holds also errors coming back as response so it's enough) then finally - Processs URL

Headers:

  1. You Construct Json Request, save as Variable
  2. You get the Request Object from it and save as Variable

The Request Object is where you set your Headers using Set Header and/or Parameters using "Set String Field" The Json Request is where you Bind the Event and Process URL

Once you get the Response (Custom Event) right afterward Get Response Content as String to see what we got back from Server, then we Get Response Object from the Response and save to Variable fo easier usage

You get the Data from the Json Object by using "Get String Field", "Get Int Field" etc. depending on the data the field holds

Example:

I Hold the crucial info in my PController and pass to a Custom Function image

If you read the steps above starting from "Headers" and follow the images you'll find your way

Most of the Requests start this way: image

Then you set your Headers and/or Paramaters In this case those are Parameters as I used "Set X Field" (X = String, Int etc.) image

Bind the Event image

And finally Process URL (The bool is just for PrintString to determine if it should be visible on Screen) image

The Response from Server: image

Like said you get the Response and make a Print String to know what is happening and what data you get back

At the end you can use that Data you've got back, as this is the 1st Guest Login I wanted to save my Session Token that we need for any further API image

Example after successful Login: From this point you need the Session Token Header to proceed with any API

image

The only thing that happens is that the Response itself is being saved into a kind of Log image

Get Player Info Function: image

Va Rest Construct Request Function (this is where we construct the Request and pass Headers image

Again same thing - we construct a Request and save Variables to use them more convenient

Afterwards (finally!) we pass Headers we need, we can pass Parameters too - simply use "Set X Field" image

Custom Verb is needed if we want to use Requests like PATCH that's not a part of the Enum by the Request Construct image

Using the Data we got from Server image

After we got the Response Object - this is what holds the information, as this was getting the Player Name I tested what is the Response, learned what Field holds the data of my interest (name) and used "Get String Field" to get that value

A bit of practice, doing mistakes and so on and you're gonna get it