Comments (7)
PR is created: #20
from fable-powerpack.
Here's an example, I hope it helps 😄
GlobalFetch.fetch(
RequestInfo.Url url,
requestProps
[ RequestProperties.Method HttpMethod.POST
requestHeaders [ContentType "application/json"]
RequestProperties.Body !^(toJson myObject) ])
fable-powerpack contains helpers for most common cases like this one. You can also check the tests.
from fable-powerpack.
I have no problems with predefined headers, but still not clear how to add custom headers.
Tests and code does not have examples.
This does not work:
let headers =
[ ContentType "application/x-www-form-urlencoded"
"API-Key", Json.Encode.string apiKey
"API-Sign", signature
]
from fable-powerpack.
@ed-ilyin Can you try something like that:
let headers =
[ ContentType "application/x-www-form-urlencoded"
!!("API-Key", Json.Encode.string apiKey)
!!("API-Sign", signature)
]
!!
comes from Fable.Core.JsInterop
I am not sure if this will work, but I saw people using this synthax for custom data attribute in Elmish and it's kind the same situation.
To explain, !!
is equivalent to unbox(".....", "......")
so it's simply make the compiler happy and Fable should convert the Key/Value into the desired object.
from fable-powerpack.
Sorry @ed-ilyin, I misread the issue 😅 Thanks for the explanation, @MangelMaxime! That's right, you can use dynamic casting to fake a key-value pair when passing values to keyValueList
. Another alternative is to add a union case with Erase
attribute to the union type.
| [<Erase>] Custom of key:string * value:obj
Then you can do:
let headers =
[ ContentType "application/x-www-form-urlencoded"
Custom("API-Key", Json.Encode.string apiKey)
// Same as !!("API-Key", Json.Encode.string apiKey) but typed
]
I just noticed the Erase
attribute is not working in these cases in the current release, but I've fixed that for the next one. Also, please not the CaseRules (like LowerFirst
letter) don't apply for custom headers.
from fable-powerpack.
I like the idea with Custom case. Should I create PR?
from fable-powerpack.
Yes, please :)
from fable-powerpack.
Related Issues (20)
- a non-beta release HOT 1
- Support for node-fetch extensions? HOT 3
- Something weird with type inference in promises HOT 6
- `Promise` doesn't provide variants of `catch` and `either` where the rejection function returns another `Promise` HOT 6
- Make `Promise.catch` and `Promise.catchBind` emit "$0.then" to make it compatible with ad-hoc implementations HOT 5
- Get the response data when the server returns 400. HOT 2
- Update README instructions
- Retrieving object when Promise fails. HOT 7
- Extending Date.Local? HOT 9
- unwrapResult function and result computation expression not defined HOT 2
- JSON deserialization of postRecord response of a DU does not work as expected HOT 6
- "h" format result is incorrect for noon HOT 6
- Please release stable version HOT 2
- Fetch: get response body in case of 5xx response HOT 2
- Promise CE is executed multiple times if there are multiple subscribers HOT 7
- Can't open project in Visual Studio HOT 3
- Fetch with Fable 2: wrong ContentType header? HOT 4
- Split Fable.PowerPack in multiple packages? HOT 3
- Fetch makes GET request first if called with POST method in case of redirect HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fable-powerpack.