API REST JSON com Harbour

543 views
Skip to first unread message

Amauri Soares de Oliveira

unread,
Sep 15, 2022, 3:25:53 PM9/15/22
to minigu...@googlegroups.com
Boa tarde.

Estou precisando integrar meu ERP com um Aplicativo para Celular Android,
e a Integração é atravéz de API REST utilizando o formato JSON, e eu não conheço nada desse método.

Alguém teria um exemplo com os comandos GET POST PUT PATCH DELETE
pra disponibilizar para meus estudos ?

Se algum colega tiver, ficarei muito grato.


Amauri S. Oliveira
ASO Sistemas
Harbour/Minigui Ext

Ross McKenzie

unread,
Sep 15, 2022, 8:18:13 PM9/15/22
to Harbour Minigui
Google translate  says...

Good afternoon. I need to integrate my ERP with an Android Mobile Application, and the Integration is through REST API using the JSON format, and I don't know anything about this method. Would anyone have an example with the commands GET POST PUT PATCH DELETE to make it available for my studies? If any colleagues have it, I would be very grateful. Amauri S. Oliveira ASO Systems Harbor/Minigui Ext

Jose Antonio Leon Tellez

unread,
Sep 16, 2022, 2:31:56 PM9/16/22
to Amauri Soares de Oliveira, minigu...@googlegroups.com
Hi Amauri,

This is a example:

***********************************************************
function webservicerest(CFILE,cfileresponse,metodo_,pdf_xml)
***********************************************************
Response:=""
if .not. file(Cfile)
   msginfo("File not found")
   return .f.
endif
Ctext:=MEMOREAD(cfile)


cTextformato:="d?e="+parameter1+"&id="+parameter2+"&t="+parameter3+"&d="+parameter1  && example for send 4 parameters in method GET

ctamano=alltrim(str(len(cText),10))
tamano=len(cText)

UsERNAME:= "xxxxxxxx"
PASSWORD:= "xxxxxxxx"
username64:=hb_base64Encode(username)
password64:=hb_base64Encode(":"+password)
mAuthorization:=hb_base64Encode(username+":"+password)
doc =   CreateObject( "MSXML2.DOMDocument" )
ohttp = CreateObject( "MSXML2.XMLHTTP" )

If (Empty( ohttp))
   MsgStop( 'Objet Create Error. ' )
   Return( .f. )
Endif

if metodo_="POST"
   ohttp:Open( "POST" ,"https://yourdomain.com/xxxxxx/xxxx/yourmethod",.F.)
ELSE
   ohttp:Open( "GET" ,"https://yourdomain.com/xxxxxx/xxxx/yourmethod"+cTextformato,.F.)
ENDIF
ohttp:SetRequestHeader("content-type", "application/json" )
ohttp:SetRequestHeader("Connection", "100-continue" )
ohttp:SetRequestHeader("Expect", "Keep-Alive" )
ohttp:SetRequestHeader("authorization", "Basic "+mAuthorization )
ohttp:SetRequestHeader("content-length",tamano)
if metodo_="POST"
   ohttp:Send(Ctext)
else
   ohttp:Send(Ctextformato)
endif
mstatus=ohttp:STATUS
if ohttp:STATUS = 200
    response:=ohttp:responseText
else
   MsgStop( "Error: Status "+str(mstatus,10) )
endif
if (Empty( response ) )
   MsgStop( "Error:  Respuesta esta VACIA.  Status "+str(mstatus,10) )
   return
End
Memowrit( cfileresponse,Response)

nLen:=0
res:={}
o=0

nLen := hb_jsondecode( response, @res )
if nlen=0
   msginfo("No data found")
   return
endif
if metodo_="POST"
   ****   example for response in format json received
      id               :=res["Id"]
      CUFE        :=res["Cufe"]
      description :=res["Description"]
      qrcode       :=res["QrCode"]
      state          :=res["State"]
      validate     :=res["Validated"]
      result        :=res["Result"]
ELSEIF metodo_="GET"
   ****   example for response in format json received
   cresult   :=res["Result"]
   cdescrip :=res["Description"]
   if cresult#0
      msginfo(Cdescrip)
   ELSE
     cDocum   :=res["Document"]   &&  here receive a string for convert to pdf or xml
     IF TYPE('cDocum')="U"
        msginfo(description)
     ELSE
        IF LEN(ALLTRIM(cdocum))=0
           msginfo(" XML  FILE is empty")
        ENDIF
        mdecode:=hb_base64Decode(cDocum)               && convert string to pdf or xml
        hb_Memowrit("newfile"+'.'+pdf_xml,mdecode)
     ENDIF
   ENDIF
else
   msginfo("Method invalid.  ---> get o post")
endif
ohttp  := NIL
Release ohttp
return

Best regards,

Jose Antonio Leon Tellez


--
Visit our website on https://www.hmgextended.com/ or https://www.hmgextended.org/
---
You received this message because you are subscribed to the Google Groups "Harbour Minigui" group.
To unsubscribe from this group and stop receiving emails from it, send an email to minigui-foru...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/minigui-forum/CACtBdbkmUEgip-csaCpVm4d-mxKmtuq%3DSbSCxgkLcXLQbTkyeQ%40mail.gmail.com.

priadi andika

unread,
Sep 17, 2022, 9:23:25 AM9/17/22
to Jose Antonio Leon Tellez, Amauri Soares de Oliveira, Harbour Minigui
Dear Jose Antonio Leon Tellez

Thank you for the sample about REST API with JSON

Do you have a web or blog..?

I want to learn a lot about this and of course other knowledge

1. Is there a sample web service?

2. Is there an access sample with functions created with other
programming languages such as PHP, etc

Best Regard
SPD

Pada tanggal Sab, 17 Sep 2022 pukul 01.31 Jose Antonio Leon Tellez
<jleo...@gmail.com> menulis:
> To view this discussion on the web, visit https://groups.google.com/d/msgid/minigui-forum/CAMqt_0VNirN8MTsCx%3D1VVnBAyNZLw6RZduSb%2ByUc3OZ_aON5fw%40mail.gmail.com.

Jose Antonio Leon Tellez

unread,
Sep 17, 2022, 11:31:26 AM9/17/22
to priadi andika, Amauri Soares de Oliveira, Harbour Minigui
Hi Priadi,

[Google traductor]:

I don't have a website or blog.

I have used two platforms to make APIs:

a) Postman :https://www.postman.com/

b) SoapUI: (https://www.soapui.org)

These tools allow you to create examples and generate the code for you in various languages.

I have used webservices to generate SMS text messages and whatsapp messages: Example:

Also to generate electronic invoices (country: Colombia) and query and download documents and databases.

Best regards,

Jose Antonio Leon Tellez



priadi andika

unread,
Sep 18, 2022, 1:56:35 AM9/18/22
to Jose Antonio Leon Tellez, Amauri Soares de Oliveira, Harbour Minigui
Helo Jose Antonio Leon Tellez

Thank you very much.

Best Regard
SPD

Pada tanggal Sab, 17 Sep 2022 pukul 22.31 Jose Antonio Leon Tellez
Reply all
Reply to author
Forward
0 new messages