Skip to content

Instantly share code, notes, and snippets.

@ivancorrales
Last active February 17, 2021 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivancorrales/23452e3460d6fee1b1060d8e92a4d8f7 to your computer and use it in GitHub Desktop.
Save ivancorrales/23452e3460d6fee1b1060d8e92a4d8f7 to your computer and use it in GitHub Desktop.
vars {
mediaJson = "application/json"
}
func signUp {
input {
arg baseApi {
description = "URL base of the API"
}
arg user {
description = "entity with attributes fullName, username & password"
}
}
body {
http post {
request {
baseUrl = baseApi
path = "/account"
headers {
Content-Type = mediaJson
}
payload json {
data = user
}
}
response {
httpResponse = {
statusCode = _.http.statusCode
body = json(_.http.body)
}
}
}
}
return {
value = httpResponse
}
}
func signIn {
input {
arg baseApi {
description = "URL base of the API"
}
arg credentials {
description = "entity with attributes username & password"
}
}
body {
http post {
request {
baseUrl = baseApi
path = "/session"
headers {
Content-Type = mediaJson
}
payload json {
data = credentials
}
}
response {
httpResponse = {
statusCode = _.http.statusCode
body = json(_.http.body)
}
}
}
}
return {
value = httpResponse
}
}
func showProfile {
input {
arg baseApi {
description = "URL base of the API"
}
arg token {
description = "a valid JWT"
}
}
body {
http get {
request {
baseUrl = baseApi
path = "/me"
headers {
x-access-token = token
}
}
response {
httpResponse = {
statusCode = _.http.statusCode
body = json(_.http.body)
}
}
}
}
return {
value = httpResponse
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment