checkcpfrestapigobind

command module
v0.0.0-...-e9e8833 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2020 License: MIT Imports: 10 Imported by: 0

README

checkCpfRestApiGoBind

RESTful API to verify physical person registers status on Brazilian entities.
A GO (Golang) API solution that dynamically binds the library CURL to manage HTTP requests.

The routing API receives a CPF (Brazilian Physical Person Register) to be checked.
Then the CPF is validated on SERPRO (Brazilian Federal Data Processing Service) that also uses a RESTful API.

The HTTP request implementation uses go-curl (github.com/andelf) package that dynamically links with the pre-installed libCurl (github.com/curl).
The libCurl is implemented in C/C++, and go-curl is powered by GO and C languages.

The API may also receives more informative data, like Name and RG (Brazilian General Registry), not being validated now.
The API routing implementation uses the library gorilla/mux (github.com/gorilla/mux).

Quick Start (on Linux)

Install GO compiler
sudo apt install gccgo-go

This application was tested with GO release 1.12.2. To check the installed version of GO compiler, run:

go version
Install Gorilla Mux router library
go get -u github.com/gorilla/mux
Install lib Curl for Development
sudo apt-get install libcurl-dev

This application was tested with the library libcurl4-openssl-dev on release 7.68.0

Install Go-Curl binding library
go get -u github.com/andelf/go-curl
Build and run checkCpfRestApiGoBind (from the project root folder)
go build
./checkCpfRestApiGoBind

API description

URL : api/v1/verify

Method : POST

Auth required : NO

Permissions required : None

Required fields : cpf

Non-required fields : name, rg (number, issued, entity)

Request example:

 {
  "name":"Heitor Peralles",
  "cpf":"40442820135",
  "rg": { "number":"209921899", "issued":"2020/5/20", "entity":"DETRAN-RJ" }
 }
Success Response

Code : 200 Register OK

Response example:

 {
  "status":"True"
 }
Error Responses

Code : 400 Invalid format or registry number

Code : 403 Problem with the registry, NOT OK

Code : 500 Server Error

Response example:

 {
  "status":"False",
  "message":"Invalid CPF Format."
 }

Testing the API

RUN Unit tests (from the project root folder)

The file app_test.go contains a collection of unit tests. Run the tests by calling the command below.

go test -v
Testing manually
A simple way to test the API on Linux:

Install CURL, the recommended library to deal with requests.

sudo apt-get install curl

Trigger a request to the primary endpoint as follows.

curl localhost:8000/api/v1/verify -i -X POST -d '{"cpf":"40442820135"}'

Remembering that checkCpfRestApiGoBind must be running to receive the request.

List of testing CPFs provided by SERPRO:

The application uses a service provided by SERPRO, so any test depends on this service being online.
The CPFs provided by SERPRO for testing are:

40442820135: Regular (Register OK)
63017285995: Regular (Register OK)
91708635203: Regular (Register OK)
58136053391: Regular (Register OK)
40532176871: Suspended (Problem with the registry)
47123586964: Suspended (Problem with the registry)
07691852312: Regularization Pending (Problem with the registry)
10975384600: Regularization Pending (Problem with the registry)
01648527949: Canceled by Multiplicity (Problem with the registry)
47893062592: Canceled by Multiplicity (Problem with the registry)
98302514705: Null (Problem with the registry)
18025346790: Null (Problem with the registry)
64913872591: Registration Canceled (Problem with the registry)
52389071686: Registration Canceled (Problem with the registry)
05137518743: Deceased Holder (Problem with the registry)
08849979878: Deceased Holder (Problem with the registry)

Implementation

File structure

The application is composed by a set of source code files:

app.go : Main file, with main() function.
app_test.go : File containing all application tests.

api_model.go : API structures.
api_routing.go : API routing implementation using Gorilla Mux.
api.go : Code to handle provided API requests and responses.

middleware_model.go : SERPRO service structures.
middleware.go : Core implementation of the request using go-curl library.

README.md : This file, explaining how the application works.
.gitignore : List of non-versioned files (such as the compiled binary).

After the compilation process, the non-versioned binary file checkCpfRestApiGoBind will be generated.

API Credentials

The application is configured with a personal TOKEN, please change it.
Its possible to generate a new TOKEN on SERPRO service page: servicos.serpro.gov.br.

The in use TOKEN is specified on the top of middleware.go file.
If going to production the SERPRO service URL must also be changed (at the same file).

Application Info

Author

Heitor Peralles
heitorgp@gmail.com
linkedin.com/in/heitorperalles

Source

github.com/heitorperalles/checkCpfRestApiGoBind

License

MIT licensed. See the LICENSE file for details.

Documentation

Overview

------------------------------------------------------------------------------ From http://github.com/heitorperalles/checkCpfRestApiGoBind

Distributed under The MIT License (MIT) <http://opensource.org/licenses/MIT>

Copyright (c) 2020 Heitor Peralles <heitorgp@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------

------------------------------------------------------------------------------ From http://github.com/heitorperalles/checkCpfRestApiGoBind

Distributed under The MIT License (MIT) <http://opensource.org/licenses/MIT>

Copyright (c) 2020 Heitor Peralles <heitorgp@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------

------------------------------------------------------------------------------ From http://github.com/heitorperalles/checkCpfRestApiGoBind

Distributed under The MIT License (MIT) <http://opensource.org/licenses/MIT>

Copyright (c) 2020 Heitor Peralles <heitorgp@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------

------------------------------------------------------------------------------ From http://github.com/heitorperalles/checkCpfRestApiGoBind

Distributed under The MIT License (MIT) <http://opensource.org/licenses/MIT>

Copyright (c) 2020 Heitor Peralles <heitorgp@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------

------------------------------------------------------------------------------ From http://github.com/heitorperalles/checkCpfRestApiGoBind

Distributed under The MIT License (MIT) <http://opensource.org/licenses/MIT>

Copyright (c) 2020 Heitor Peralles <heitorgp@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------

------------------------------------------------------------------------------ From http://github.com/heitorperalles/checkCpfRestApiGoBind

Distributed under The MIT License (MIT) <http://opensource.org/licenses/MIT>

Copyright (c) 2020 Heitor Peralles <heitorgp@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL